(function ($, owner) {
    // var httpUrl = "http://10.211.55.2:8088"; // 单病种服务url
    // 是否显示工具栏或者图标（与CDSS合并时不需要显示单病种自身的图标）
    var isShowIcon = true;
    var currentData = {};
    var config = {
        CDSSServer:'',   // CDSS的Web服务地址
        float_drg_show:'',   //浮窗是否显示Drg展示按钮
        float_pre_filling:'', //浮窗预填报按钮是否显示
        WebSocket_Entity:''//支持Websocket自动刷新的病种
    };
    var inOutTip = ""; // 出入组提示
    var inOutTipNum = 0; // 出入组提示消息数
    var planDoTips = ""; // 诊疗辅助事项提示
    var planDoTipsNum = 0; // 诊疗辅助事项提示消息数
    var qcTips = ""; // 质控提示
    var qcTipsNum = 0; // 质控提示消息数
    var ciTips = ""; // 禁忌提示
    var ciTipsNum = 0; // 禁忌提示消息数
    var tipStr = "";
    var tipsNum = 0;
    var drgTips = ""; // drg费用提示
    var drgTipsNum = 0; // drg费用提示消息数
    var doItem = ""; // 当前操作事件

    // 单病种质控数量成员变量
    owner.sdsNum = 0;
    if (!isShowIcon) {
        DHCDSSNavConfig.SDS.show = function(){
            saveLog("open")
            $("#app-cdss").show();
        }
    }


    // 获取sdstool当前所在目录
    var find = function (str,cha,num){
        var x=str.indexOf(cha);
        for(var i=0;i<num;i++){
            x=str.indexOf(cha,x+1);
        }
        return x;
    }
    var getSrcHost = function () {
        var jsPath = document.currentScript ? document.currentScript.src : function () {
            var js = document.scripts, last = js.length - 1, src;
            for (var i = last; i > 0; i--) {
                if (js[i].readyState === 'interactive') {
                    src = js[i].src;
                    break;
                }
            }
            return src || js[last].src;
        }();
        return jsPath.substring(0, find(jsPath,'/', 2));
    };
    var httpUrl = getSrcHost(); // 单病种服务url

    var qcentity = {
        id: null, // 病种id
        name: "", // 病种名称
        code: "" // 病种代码
    };
    var cdssInfo=[]
    var params = {
        episodeId: "", // 就诊号
        paMrno: "", // 病案号
        userCode: "", // 用户代码
        userName: "", // 用户名称
        deptCode: "", // 科室代码
        deptDesc: "", // 科室名称
        pageSource: "", // 页面来源（数据类型）1 诊断录入 2 医嘱录入 3 ...
        diagInfo: // 结构化诊断信息
            [
                {
                    diagType: "", // 诊断类型 1 初步诊断 2 入院诊断 3 出院诊断
                    diagName: "", // 诊断描述
                    diagICD: "", // 诊断ICD编码
                    diagDate: "", // 诊断时间（格式： yyyy-MM-dd HH:mm:ss）
                    isMain: "" // 是否主诊断 N 否 Y 是
                }
            ]
    };

    var websocket = null;

    //动态引入js。IE下摸索到这个方法，其他浏览器无影响
    function loadScript(url, callback) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        if (typeof (callback) != "undefined") {
            if (script.readyState) {
                script.onreadystatechange = function () {
                    if (script.readyState == "loaded" || script.readyState == "complete") {
                        script.onreadystatechange = null;
                        callback();
                    }
                };
            } else {
                script.onload = function () {
                    callback();
                };
            }
        };
        script.src = url;
        document.body.appendChild(script);
    }

    function loadConfig() {
        $.ajax({
            url: httpUrl + "/api/sdstool/config",
            data: params,
            async: false,
            success: function (res) {
                config = res.data;
                console.log("引入配置成功");
            },
            error: function(res) {
                MaskIt($('#cdss'), "单病种服务异常，请联系管理员！");
            }
        });
        return config
    }

    $(function(){

        //加载js、css
        var sdsHeadStr = "<link rel='stylesheet' href='" + httpUrl + "/static/libs/layui/css/layui.css' media='all'>"
            + "<link rel='stylesheet' href='" + httpUrl + "/static/libs/hisui/css/hisui.css' media='all'>"
            + "<link rel='stylesheet' href='" + httpUrl + "/static/libs/font-awesome/font-awesome.min.css'>"
            + "<link rel='stylesheet' href='" + httpUrl + "/mediway/sds/css/style.css'>"
            + "<link rel='stylesheet' href='" + httpUrl + "/mediway/sds/css/sdstool.css'>"
            + "<script src='" + httpUrl + "/static/libs/echarts/echarts5.4.3.min.js' charset='utf-8'></script>"
            // + "<script src='" + httpUrl + "/static/libs/layui/layui.js' charset='utf-8' defer='true'></script>"
            + "<script src='" + httpUrl + "/static/libs/hisui/js/jquery.hisui.js' charset='utf-8' defer='true'></script>";
        // document.write("<script src='" + httpUrl + "/static/libs/layer/layer.js' charset='utf-8'></script>");

        loadScript(httpUrl + "/static/libs/layui/layui.js", function() {
            console.log('动态引入layui成功')
        });
        loadConfig();

        //加载功能框
        var sdsDivStr = "<div id=\"app-cdss\" class=\"CDSSContainer\" style=\"display: none\">\n" +
            "        <!--新版锚点的UI-->\n" +
            "        <div id=\"menudiv\" style=\"display: none\">\n" +
            "            <div id=\"titlediv\"><div id=\"title1\">单病种</div><div id=\"title2\">质控</div></div>\n" +
            "            <div id=\"maodiandiv\">\n" +
            "                <div class=\"maodiantitle cdssdiv\" onclick=\"SdsTool.CountClick('TreatMenu')\">\n" +
            "                    <span>诊疗辅助</span>" +
            "                    <span id=\"cdssStatus1\" title='CDSS服务接口异常'><i class=\"fa fa-exclamation\" /></span>\n" +
            "                    <div style=\"margin-top:20px;z-index:999;display: none;\" class=\"samllTitle\">\n" +
            "                        <div class=\"maodianHover\" onclick=\"SdsTool.goAnchor('#ExamCont','诊疗辅助','推荐检查')\">推荐检查</div>\n" +
            "                        <div class=\"maodianHover\" onclick=\"SdsTool.goAnchor('#LabCont','诊疗辅助','推荐检验')\">推荐检验</div>\n" +
            "                        <div class=\"maodianHover\" onclick=\"SdsTool.goAnchor('#RatiCont','诊疗辅助','推荐评估量表')\">推荐评估量表</div>\n" +
            "                        <div class=\"maodianHover\" onclick=\"SdsTool.goAnchor('#TreaCont','诊疗辅助','推荐治疗方法')\">推荐治疗方法</div>\n" +
            "                        <div class=\"maodianHover\" onclick=\"SdsTool.goAnchor('#NursCont','诊疗辅助','推荐护理处置')\">推荐护理处置</div>\n" +
            "                    </div>\n" +
            "                </div>\n" +
            "                <div class=\"qcdiv\"  style=\"font-size:14px;color:white;margin-top:20px;position:relative;cursor: pointer;\" onclick=\"SdsTool.CountClick('WarnMenu')\">\n" +
            "                <span>质控提醒</span>" +
            "                <div id=\"WarnNumber1\"></div>\n" +
            "                </div>\n";
            // "                <div class=\"cidiv\"  style=\"font-size:14px;color:white;margin-top:20px;position:relative;cursor: pointer;\" onclick=\"SdsTool.CountClick('CIMenu')\">\n" +
            // "                <span>预警信息</span>" +
            // "                <div id=\"CINumber1\"></div>\n" +
            // "                </div>\n"
        if (config.float_drg_show == 'Y') {
            sdsDivStr +=
                "                <div class=\"drgdiv\"  style=\"font-size:14px;color:white;margin-top:20px;position:relative;cursor: pointer;\" onclick=\"SdsTool.CountClick('DRGMenu')\">\n" +
                "                <span>费用相关</span>" +
                "                </div>\n"
        }
        sdsDivStr+=
            "            </div>\n" +
            "            <div id=\"buttondiv\">\n" +
            "                <img style=\"width:60px\" src=\"" + httpUrl + "/mediway/sds/img/companyLogo.png\">\n" +
            "                <span style=\"font-size:12px;color:white;opacity:0.3\">SDSv2.0@</span>\n" +
            "                <div class=\"MZDiv1\">\n" +
            "                <span style=\"font-size:12px;color:white;display:block;opacity:0.3\">免责声明</span>\n" +
            "                <div class=\"MZDesc1\">\n" +
            "                    <div class=\"MZTitle\">免责声明</div>\n" +
            "                    <div class=\"MZContent\">本系统所有的文章、课件、图片及其他资源，版权归原始作者所有，未经允许，严禁将本系统内容用于商业用途，本系统的内容出于传递信息目的，仅供个人学习使用，不意味赞同其观点或证实其描述，不可替代医师诊断或处方，具体诊疗请详询专科医生，本系统不承担由此导致的相关责任。</div>\n" +
            "                </div>\n" +
            "                </div>\n" +
            "                <img onclick=\"SdsTool.openMenu(0)\" style=\"display:block;padding-left:35px;padding-top:20px\" src=\"" + httpUrl + "/mediway/sds/img/foldRight.png\">\n" +
            "                <img onclick=\"SdsTool.minimize()\" style=\"display:block;padding-left:35px;padding-top:10px\" src=\"" + httpUrl + "/mediway/sds/img/minimize.png\">\n" +
            "            </div>\n" +
            "        </div>\n" +
            "        <!--缩小后的导航-->\n" +
            "        <div id=\"smallMenuDiv\">\n" +
            "            <div id=\"smalltitlediv\">单病种</div>\n" +
            "            <div id=\"smallmaodiandiv\">\n" +
            "                <div onclick=\"SdsTool.CountClick('TreatMenu')\" style=\"padding-top:20px\" class=\"iconButton\"><img class=\"smallMenuImg cdssdiv\" style=\"padding:5px 5px\" title=\"诊疗辅助\" src=\"" + httpUrl + "/mediway/sds/img/treat.png\">\n" +
            "                    <span id=\"cdssStatus\" title='CDSS服务接口异常'><i class=\"fa fa-exclamation\" /></span>\n" +
            "                </div>\n" +
            "                <div onclick=\"SdsTool.CountClick('WarnMenu')\" style=\"padding-top:20px\" class=\"iconButton\"><img class=\"smallMenuImg qcdiv\" style=\"padding:5px 5px\" title=\"质控提醒\" src=\"" + httpUrl + "/mediway/sds/img/warn.png\">\n" +
            "                    <div id=\"WarnNumber\"></div>\n" +
            "                </div>\n" ;
            // "                <div onclick=\"SdsTool.CountClick('CIMenu')\" style=\"padding-top:0px\" class=\"iconButton\"><img class=\"smallMenuImg cidiv\" style=\"padding:5px 5px\" title=\"预警信息\" src=\"" + httpUrl + "/mediway/sds/img/CI.png\">\n" +
            // "                    <div id=\"CINumber\"></div>\n" +
            // "                </div>\n"

        if (config.float_drg_show == 'Y') {
            sdsDivStr +=
                "                <div onclick=\"SdsTool.CountClick('DRGMenu')\" style=\"padding-top:0px\" class=\"iconButton\"><img class=\"smallMenuImg drgdiv\" style=\"padding:5px 5px\" title=\"费用信息\" src=\"" + httpUrl + "/mediway/sds/img/fee.png\">\n" +
                "                    <div id=\"CINumber\"></div>\n" +
                "                </div>\n"
        }

        sdsDivStr+=
            "            </div>\n" +
            "            <div id=\"smallbuttondiv\">\n" +
            "                <div class=\"MZDiv\">\n" +
            "                <div style=\"font-size:12px;color:white;display:block;opacity:0.3\">免</div>\n" +
            "                <div class=\"MZDesc\">\n" +
            "                    <div class=\"MZTitle\">免责声明</div>\n" +
            "                    <div class=\"MZContent\">本系统所有的文章、课件、图片及其他资源，版权归原始作者所有，未经允许，严禁将本系统内容用于商业用途，本系统的内容出于传递信息目的，仅供个人学习使用，不意味赞同其观点或证实其描述，不可替代医师诊断或处方，具体诊疗请详询专科医生，本系统不承担由此导致的相关责任。</div>\n" +
            "                </div>\n" +
            "                </div>\n" +
            "                <img onclick=\"SdsTool.openMenu(1)\" style=\"display:block;padding-left:4px;padding-top:10px\" src=\"" + httpUrl + "/mediway/sds/img/foldLeft.png\">\n" +
            "                <img onclick=\"SdsTool.minimize(1)\" style=\"display:block;padding-left:4px;padding-top:10px\" src=\"" + httpUrl + "/mediway/sds/img/minimize.png\">\n" +
            "            </div>\n" +
            "        </div>\n" +
            "       <!--CDSS内容主体模块-->\n" +
            "       <div id=\"plane\" class=\"PlaneContainer\">\n" +
            "           <div class=\"Container\" unselectable=\"on\" onselectstart=\"return false;\"\n>" +
            "               <div id=\"EntityDiv\">\n" +
            "                   <span id=\"entityName\" style='display:block;width:200px;height:30px;overflow:hidden;float:left;'>" + qcentity.name + "</span>\n" +
            "                   <a href=\"javascript:SdsTool.showDetail()\" title='治疗情况' ><img src='" + httpUrl + "/mediway/sds/img/detail.png'/></a>\n" +
            "                   <a href=\"javascript:SdsTool.outofGroup()\" title='手动出组' ><img src='" + httpUrl + "/mediway/sds/img/out.png'/></a>\n"
        if (config.float_pre_filling == 'Y') {
            sdsDivStr +=
                "                   <a href=\"javascript:SdsTool.showForm()\" title='预填报' style='margin-right:12px '><img src='" + httpUrl + "/mediway/sds/img/treat.png'/></a>\n"

        }
        sdsDivStr+=
            "               </div>" +
            "               <div id=\"cdssStatusMsg\"></div>\n" +
            "               <div id=\"cdss\"></div>\n" +
            "               <div id=\"batch\"></div>\n" +
            "               <template id=\"ci-temp\">\n" +
            "                   <div class=\"SuspectedContainer\" style=\"overflow-y: auto\">\n" +
            "                       <div id=\"ciItems\">\n" +
            "                           <div class=\"standardWord\"></div>\n" +
            "                           <div class=\"standardDesc\">\n" +
            "                               <input class=\"hisui-checkbox\" type=\"checkbox\" label=\"\" name=\"\" id=\"\">\n" +
            "                           </div>\n" +
            "                       </div>\n" +
            "                   </div>\n" +
            "                     <div class=\"ButtonCont\">\n" +
            "                       <button class=\"ButtonItem\" id=\"batchConfirm\" onclick=\"SdsTool.getSelected(this)\">确认</button>\n" +
            "                       <button class=\"ButtonItem\" id=\"batchReturn\" onclick=\"SdsTool.sendMsg()\">返回</button>\n" +
            "                     </div>\n" +
            "                   </div>\n" +
            "               </template>" +
            "           </div>\n" +
            "       </div>\n" +
            "</div>  ";
        // 是否显示工具栏或者图标（与CDSS合并时不需要现实图标）
        if (isShowIcon) {
            // 工具栏样式
            /*sdsDivStr += '<div class="toolbar" id="toolbar" flag="open">' +
                // '<a class="icon" href="javascript:SdsTool.showPatientInfo()"><i class="fa fa-user fa-2x fa-inverse" ></i></a>' +
                '<a id="" href="javascript:SdsTool.displayArea()"><i id="expand" class="fa fa-caret-down fa-2x fa-inverse" aria-hidden="true"></i> </a>' +
                '<a class="icon" href="javascript:SdsTool.openSdsWindow()">' +
                '  <i class="fa fa-bell fa-2x fa-inverse" ></i><div class="alarm">' + tipsNum + '</div>' +
                '</a>' +
                '<a class="icon" href="javascript:SdsTool.showCDSS()"><i class="fa fa-book fa-2x fa-inverse" ></i></a>' +
                '<a class="icon" href="javascript:SdsTool.showSearch()"><i class="fa fa-search fa-2x fa-inverse" ></i></a>' +
                '<i class="fa fa-arrows fa-2x fa-inverse" ></i>' +
                '</div>';*/
            // 独立图标样式
            sdsDivStr += '<div class="iconBar" id="toolbar" flag="open">' +
                '<a class="icon" href="javascript:SdsTool.openSdsWindow()">' +
                '  <img src=\'' + httpUrl + '/mediway/sds/icon/SDS.png\' /><div class="alarm iconAlarm">' + tipsNum + '</div>' +
                '</a>' +
                '</div>';
        }

        var head = document.head;
        var body = document.body;
        $(head).append(sdsHeadStr);
        $(body).append(sdsDivStr);
    });

    /**
     *设置参数格式
     */
    owner.setParams = function (paramsobj) {
        // var initParams = {
        //         episodeId: "", // 就诊号
        //         registerId: "", // 登记号
        //         paMrno: "", // 病案号
        //         userCode: "", // 医生代码
        //         userName: "", // 医生名称
        //         deptCode: "", // 科室代码
        //         deptDesc: "" // 科室名称
        //     },
        paramsobj = paramsobj || {};
        for (var key in paramsobj) {
            //var nkey=key.toUpperCase
            // initParams[key] = paramsobj[key];
            params[key] = paramsobj[key];
        }
        // params = initParams;
        // return initParams;
        return params;
    };

    /**
     * 清除临床业务数据
     */
    owner.clearParams = function () {
        params.pageSource = "";
        params.diagInfo = [];
    };

    /**
     * 新建websocket连接
     */
    owner.newWebSocket = function (){
        var host = httpUrl.split("://")[1]
        if (websocket != null){
            websocket.close();
            websocket = null;
        }
        var entityIds = config.WebSocket_Entity.split(',');
        var mark = 0;
        for (var i = 0; i < entityIds.length; i++) {
            var entity = entityIds[i];
            if (entity == currentData[0].entityId) {
                mark = 1;
                break;
            }
        }
        if (mark == 0){
            return;
        }
        //判断当前浏览器是否支持WebSocket
        if ('WebSocket' in window) {
            var url = "ws://" + host + "/api/websocket/server"
            websocket = new WebSocket(url);
        } else {
            alert('浏览器不支持webSocket');
        }
        //连接发生错误的回调方法
        websocket.onerror = function () {
            console.log("webSocket错误");
        };
        //连接成功建立的回调方法
        websocket.onopen = function (event) {
            console.log("成功建立webSocket连接");
        };
        //接收到消息的回调方法
        websocket.onmessage = function (event) {
            var data = event.data;
            console.log("后端传递的数据:" + data);
            if (data==params.episodeId){
                params.t = new Date().getTime(); //IE相同参数下，ajax不会重复请求
                params.type = '';
                $.ajax({
                    url: httpUrl + "/api/sdstool/init",
                    data: params,
                    async: true,
                    success: function (res) {
                        currentData = res.data;
                        owner.loadTips();
                    }
                });
            }
        };
        //连接关闭的回调方法
        websocket.onclose = function () {
            console.log("成功关闭webSocket连接");
        };
        //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
        window.onbeforeunload = function () {
            closeWebSocket();
        };
        //关闭连接
        function closeWebSocket() {
            websocket.close();
        }
        //发送消息
        function send() {
            var message = document.getElementById('text').value;
            websocket.send(message);
        }
    }

    /**
     * 第三方调用之前 初始化页面方法
     */
    owner.loader = function (param) {
        // 设置患者参数
        this.setParams(param);
        // 切换患者后关闭已打开的窗口，重置提醒数量、清空诊疗数据、病种信息
        $("#app-cdss").hide();
        $("#toolbar").show();
        clearArea();
        tipStr = inOutTip = planDoTips = qcTips = "<div class=\"fixed-box\">\n" +
            "        <img style=\"margin-top: 150px;\" src=\"" + httpUrl + "/mediway/sds/img/nodataimg.png\">\n" +
            "     </div>";
        $("#cdss").html(planDoTips);
        $("#batch").html(qcTips);
        owner.sdsNum = 0;
        if (!isShowIcon) {
            DHCDSSNavConfig.initNavStatus();
            DHCDSSNavConfig.changeNavWarnNum("sds",owner.sdsNum);
        }
        // 初始化
        owner.init();
        // 组装信息
        // owner.loadTips();
    };


    /**
     * 同步患者诊断数据
     */
    owner.synClinicData = function(dataType) {
        params.dataType = dataType;
        $.ajax({
            url: httpUrl + "/api/sdstool/synData",
            data: params,
            async: true,
            success: function (res) {
                // currentData = res.data;
                // owner.loadTips();
                owner.analysis();
            }
        });
    };

    /**
     * 推送患者数据
     * dataType : 数据类型
     * dataStr: 数据json串
     */
    owner.PushDataToDHCSDS = function(dataType, dataStr) {
        params.action = dataType;
        params.message = dataStr;
        $.ajax({
            url: httpUrl + "/api/SdsMessageServer",
            type: 'post',
            data: params,
            async: true,
            success: function (res) {
                owner.analysis();
            }
        });
    };

    /**
     * 传送临床数据，进行分析
     */
    owner.sendData = function () {
        // 分析
        owner.analysis();
        // 组装
        // owner.loadTips();
        // 展示
        // owner.openSdsWindow();
        // 清空业务数据
        owner.clearParams();
    };

    /**
     * 请求后台，初始化患者信息
     */
    owner.init = function () {
        params.t = new Date().getTime(); //IE相同参数下，ajax不会重复请求
        $.ajax({
            url: httpUrl + "/api/sdstool/init",
            data: params,
            async: true,
            success: function (res) {
                currentData = res.data;
                // 如果当前js中就诊号与请求返回数据中就诊号相同才加载数据
                // 目的是解决因为异步请求问题，当快速切换两个患者并行请求数据，因为第1个患者执行时长比第2个患者晚，导致的1覆盖2的数据问题
                if (params.episodeId == res.curEpisodeId) {
                    owner.newWebSocket();
                    owner.loadTips();
                }
            },
            error: function(res) {
                MaskIt($('#cdss'), "单病种服务异常，请联系管理员！");
            }
        });
    };

    /**
     * 请求后台，重新获取数据
     */
    owner.reload = function (dataType) {
        params.t = new Date().getTime(); //IE相同参数下，ajax不会重复请求
        params.type = dataType;
        $.ajax({
            url: httpUrl + "/api/sdstool/init",
            data: params,
            async: false,
            success: function (res) {
                currentData = res.data;
                owner.loadTips();
            }
        });
    };

    /**
     * 请求推荐信息
     */
    owner.reloadTreatInfo = function () {
        $.ajax({
            url: httpUrl + "/api/sdstool/reloadTreatInfo",
            data: {"episodeId": params.episodeId, "entityId": qcentity.id, t:new Date().getTime()},
            async: false,
            success: function (treatInfo) {
                owner.treatMsg(treatInfo[0],treatInfo[1]);
            }
        });
    }

    owner.reloadTreatCiInfo = function () {
        $.ajax({
            url: httpUrl + "/api/sdstool/reloadCIInfo",
            data: {"episodeId": params.episodeId, "entityId": qcentity.id, t:new Date().getTime()},
            async: false,
            success: function (ciInfo) {
                owner.treatMsg(cdssInfo,ciInfo);
            }
        });
    }

    /**
     * 请求质控信息
     */
    owner.reloadQCInfo = function () {
        $.ajax({
            url: httpUrl + "/api/sdstool/reloadQCInfo",
            data: {"episodeId": params.episodeId, "entityId": qcentity.id, t:new Date().getTime()},
            async: false,
            success: function (qcInfo) {
                owner.qcMsg(qcInfo);
            }
        });
    }

    /**
     * 请求禁忌症信息
     */
    owner.reloadCIInfo = function () {
        $.ajax({
            url: httpUrl + "/api/sdstool/reloadCIInfo",
            data: {"episodeId": params.episodeId, "entityId": qcentity.id, t:new Date().getTime()},
            async: false,
            success: function (ciInfo) {
                owner.CIMsg(ciInfo);
            }
        });
    }

    /**
     * 请求DRG费用信息
     */
    owner.reloadDRGInfo = function () {
        $.ajax({
            url: httpUrl + "/api/sdstool/reloadDRGInfo",
            data: {"episodeId": params.episodeId, "entityId": qcentity.id, t:new Date().getTime()},
            async: false,
            success: function (drgInfo) {
                owner.DRGMsg(drgInfo.data);
            }
        });
    }

    /**
     * 请求后台，返回提示信息
     */
    owner.analysis = function () {
        params.t = new Date().getTime(); //IE相同参数下，ajax不会重复请求
        $.ajax({
            url: httpUrl + "/api/sdstool/analysis",
            data: params,
            async: true,
            success: function (res) {
                currentData = res.data;
                owner.loadTips();
            }
        });
    };

    /**入组提醒*/
    owner.inMsg = function (inoutInfo) {
        var newDisId = inoutInfo.newDisId;
        // 出组则清除之前所有消息
        tipStr = inOutTip = planDoTips = qcTips = "<div class=\"fixed-box\">\n" +
            "        <img style=\"margin-top: 150px;\" src=\"" + httpUrl + "/mediway/sds/img/nodataimg.png\">\n" +
            "     </div>";
        tipsNum = inOutTipNum = planDoTipsNum = qcTipsNum = 0;
        planDoTips = "<div class=\"inOutContent SuspectedContainer\">\n" +
            "<span>" + inoutInfo.intOutMsg + "</span>" +
            "<div class=\"ButtonCont\">\n" +
            "  <button class=\"ButtonItem green-bg\" id=\"batchConfirm\" onclick=\"SdsTool.confirmInDis(\'" + newDisId + "\')\">已知悉</button>\n" +
            // "  <button class=\"ButtonItem gray-bg\" id=\"batchReturn\" onclick=\"SdsTool.ignoreInOut(\'\'"+",\'"+newDisId+"\')\">忽略</button>\n"+
            "</div>\n" +
            "</div>\n";
        inOutTipNum++;

        if (inOutTipNum === 0) {
            $(".alarm").text(inOutTipNum).hide();
            $("#WarnNumber").text(qcTipsNum);
            $("#WarnNumber1").text(qcTipsNum);
        } else {
            $(".alarm").text(inOutTipNum).show();
            $("#WarnNumber").text(qcTipsNum);
            $("#WarnNumber1").text(qcTipsNum);
        }
    }

    /**出组提醒*/
    owner.outMsg = function (inoutInfo) {
        var curMrListId = inoutInfo.curMrListId;
        var newDisId = inoutInfo.newDisId;
        // 出组则清除之前所有消息
        tipStr = inOutTip = planDoTips = qcTips = "<div class=\"fixed-box\">\n" +
            "        <img style=\"margin-top: 150px;\" src=\"" + httpUrl + "/mediway/sds/img/nodataimg.png\">\n" +
            "     </div>";
        tipsNum = inOutTipNum = planDoTipsNum = qcTipsNum = 0;
        planDoTips = "<div class=\"inOutContent SuspectedContainer\">\n" +
            "<span>" + inoutInfo.intOutMsg + "</span>" +
            "<div class=\"ButtonCont\">\n" +
            "  <button class=\"ButtonItem green-bg\" id=\"batchConfirm\" onclick=\"SdsTool.confirmOutDis(\'" + curMrListId + "\',\'" + newDisId + "\')\">已知悉</button>\n" +
            // "  <button class=\"ButtonItem gray-bg\" id=\"batchReturn\" onclick=\"SdsTool.ignoreInOut(\'"+curMrListId+"\',\'"+newDisId+"\')\">忽略</button>\n"+
            "</div>\n" +
            "</div>\n";
        inOutTipNum++;
        if (inOutTipNum === 0) {
            $(".alarm").text(inOutTipNum).hide();
        } else {
            $(".alarm").text(inOutTipNum).show();
        }
        $("#WarnNumber").text('');
        $("#WarnNumber1").text('');
    }

    /**
     * 入组确认
     * @param newDisId
     */
    owner.confirmInDis = function (newDisId) {

        var X = $("#app-cdss")[0].offsetLeft + 100;  //获取窗口x坐标
        var Y = $("#app-cdss")[0].offsetTop + 100; //获取窗口y坐标

        var map = {};
        map.episodeId = params.episodeId;
        map.modifyUserId = params.userCode;
        map.modifyUserName = params.userName;
        map.newDisId = newDisId;
        map.t = new Date().getTime();
        $.ajax({
            url: httpUrl + "/api/sdstool/confirmInDis",
            data: map,
            async: false,
            success: function (res) {
                if (res > 0) {
                    owner.reload();
                    // owner.CountClick('TreatMenu');
                    $("#cdss").html(planDoTips);
                    $(".cdssdiv").addClass("menuSelection");
                    $("#cdss").show();
                    $("#batch").hide();
                    owner.bindOnClick();
                } else {
                    layer.msg("保存失败！", {offset: [Y, X]});
                }
            }
        });
    }

    /**
     * 出组或变更确认
     * @param newDisId
     */
    owner.confirmOutDis = function (curMrListId, newDisId) {
        var X = $("#app-cdss")[0].offsetLeft + 100;  //获取窗口x坐标
        var Y = $("#app-cdss")[0].offsetTop + 100; //获取窗口y坐标

        var map = {};
        map.episodeId = params.episodeId;
        map.modifyUserId = params.userCode;
        map.modifyUserName = params.userName;
        map.newDisId = newDisId;
        map.curMrListId = curMrListId;
        map.t = new Date().getTime();
        $.ajax({
            url: httpUrl + "/api/sdstool/confirmOutDis",
            data: map,
            async: false,
            success: function (res) {
                if (res > 0) {
                    owner.reload();
                    // owner.CountClick('TreatMenu');
                    $("#cdss").html(planDoTips);
                    $(".cdssdiv").addClass("menuSelection");
                    $("#cdss").show();
                    $("#batch").hide();
                    owner.bindOnClick();
                } else {
                    layer.msg("保存失败！", {offset: [Y, X]})
                }
            }
        });
    }

    /**
     * 忽略入出组
     */
    owner.ignoreInOut = function (curMrListId, newDisId) {
        var X = $("#app-cdss")[0].offsetLeft+ 100;  //获取窗口x坐标
        var Y = $("#app-cdss")[0].offsetTop + 100; //获取窗口y坐标

        var map = {};
        map.episodeId = params.episodeId;
        map.modifyUserId = params.userCode;
        map.modifyUserName = params.userName;
        map.newDisId = newDisId;
        map.curMrListId = curMrListId;
        map.t = new Date().getTime();
        $.ajax({
            url: httpUrl + "/api/sdstool/ignoreInOut",
            data: map,
            async: false,
            success: function (res) {
                if (res.code === 200) {
                    owner.reload();
                    // owner.CountClick('TreatMenu');
                    $("#cdss").html(planDoTips);
                    $(".cdssdiv").addClass("menuSelection");
                    $("#cdss").show();
                    $("#batch").hide();
                    owner.bindOnClick();
                } else {
                    layer.msg("保存失败！", {offset: [Y, X]});
                }
            }
        });
    }

    /**诊疗辅助提醒*/
    owner.treatMsg = function (cdssInfo,ciInfo) {
        planDoTips = "";
        planDoTipsNum = 0;
        var examContent = "";
        var labContent = "";
        var treatContent = "";
        var nursingContent = "";
        var assessContent = "";
        var l = cdssInfo.length;
        for (var i = 0; i < l; i++) {
            var inter = cdssInfo[i];
            var interfaceValue = inter.InterfaceValue;
            var itemLen = interfaceValue.length;
            if (itemLen == 0) {
                continue;
            }
            var interfaceName = inter.InterfaceName;
            switch (interfaceName) {
                case "推荐检验检查":
                    var examItemStr = inter.InterfaceExamItemStr;
                    var labItemStr = inter.InterfaceLabItemStr;
                    var examStr = "<div id=\"ExamCont\" class=\"SuspectedContainer\" >";
                    examStr += "<div class=\"CaptionRect\" >";
                    examStr += "<div class=\"titleName\" >推荐检查</div>";
                    examStr += "<span class=\"fengeLine\">//////////////////</span>";
                    examStr += "<span class=\"BatchIcon\" onclick=\"SdsTool.showBatchOrder('','" + examItemStr + "','exam','')\">批</span>";
                    examStr += "</div>";
                    var labStr = "<div id=\"LabCont\" class=\"SuspectedContainer\" >";
                    labStr += "<div class=\"CaptionRect\" >";
                    labStr += "<div class=\"titleName\" >推荐检验</div>";
                    labStr += "<span class=\"fengeLine\">//////////////////</span>";
                    labStr += "<span class=\"BatchIcon\" onclick=\"SdsTool.showBatchOrder('','" + labItemStr + "','lab','')\">批</span>";
                    labStr += "</div>";
                    var examNum = 0;
                    var labNum = 0;
                    for (var m = 0; m < itemLen; m++) {
                        var item = interfaceValue[m];
                        var itemType = item.ItemType;
                        var itemName = item.ItemName;
                        if (itemName == "") continue;
                        var itemDesc = item.ItemDesc;
                        var treatSource = item.TreatSource;
                        var ruleBasisHtml = item.RuleBasisHtml;
                        var itemId = item.ItemID;
                        var cureId = item.CureId;
                        var sourceFlag = item.SourceFlag;
                        var bookStr = "";
                        var clazz = "";
                        var qcId = item.QCID;
                        var qcIcon = "fa-bookmark";
                        if (qcId != undefined) {
                            qcIcon = "fa-star";
                        }
                        if (itemType == "122") {
                            examNum++;
                            if (examNum > 3) {
                                clazz = "more";
                            }
                            examStr += "<div class=\"" + clazz + "\" id=\"" + itemId + "\" style=\"margin-top: 5px;\"><div class=\"itemTitle\">" +
                                "<i class=\"fa " + qcIcon + "\" aria-hidden=\"true\"></i>" +
                                "<span>" + itemName + "</span>" +
                                "<span class=\"KaiIcon\" onclick=\"SdsTool.showBatchOrder('" + itemName + "','" + itemId + "','exam','')\">开</span></div>";
                            if (sourceFlag == 1) {
                                bookStr = "<img src=\"" + httpUrl + "/mediway/sds/img/book.png\" onclick=\"SdsTool.showBook('" + treatSource + "','"+ruleBasisHtml + "')\">";
                            }
                            if (itemDesc != "" && itemDesc != null) {
                                examStr += "<div class=\"itemDesc\" title=\"" + itemDesc + "\">";
                                if ((itemDesc.split("。").length > 1 && itemDesc.split("。")[1] == "") || itemDesc.split("。").length <= 1) {
                                    examStr += "<span class=\"DisplayDesc\">" + itemDesc + "</span>" + bookStr;
                                } else {
                                    examStr += "<span class=\"DisplayDesc\">" + itemDesc.split("。")[0] + "。</span>" + bookStr + "<span class=\"MoreCont\">展开</span>";
                                }
                                examStr += "</div>";
                            }
                            examStr += "</div>";
                        } else {
                            labNum++;
                            if (labNum > 3) {
                                clazz = "more";
                            }
                            labStr += "<div class=\"" + clazz + "\" id=\"" + itemId + "\" style=\"margin-top: 5px;\"><div class=\"itemTitle\">" +
                                "<i class=\"fa " + qcIcon + "\" aria-hidden=\"true\"></i>" +
                                "<span>" + itemName + "</span>" +
                                "<span class=\"KaiIcon\" onclick=\"SdsTool.showBatchOrder('" + itemName + "','" + itemId + "','lab','')\">开</span></div>";
                            if (sourceFlag == 1) {
                                bookStr = "<img src=\"" + httpUrl + "/mediway/sds/img/book.png\" onclick=\"SdsTool.showBook('" + treatSource + "','"+ruleBasisHtml + "')\">";
                            }
                            if (itemDesc != "" && itemDesc != null) {
                                labStr += "<div class=\"itemDesc\" title=\"" + itemDesc + "\">";
                                if ((itemDesc.split("。").length > 1 && itemDesc.split("。")[1] == "") || itemDesc.split("。").length <= 1) {
                                    labStr += "<span class=\"DisplayDesc\">" + itemDesc + "</span>" + bookStr;
                                } else {
                                    labStr += "<span class=\"DisplayDesc\">" + itemDesc.split("。")[0] + "。</span>" + bookStr + "<span class=\"MoreCont\">展开</span>";
                                }
                                labStr += "</div>";
                            }
                            labStr += "</div>";
                        }
                    }

                    if (examNum > 3) {
                        examStr += " <div class=\"text-center\"><a class=\"btn show-more-btn\">点击加载更多</a></div>";
                    }

                    if (labNum > 3) {
                        labStr += " <div class=\"text-center\"><a class=\"btn show-more-btn\">点击加载更多</a></div>";
                    }
                    examStr += "</div>";
                    labStr += "</div>";
                    if (examNum > 0) {
                        planDoTipsNum++;
                        examContent = examStr;
                    }
                    if (labNum > 0) {
                        planDoTipsNum++;
                        labContent = labStr;
                    }
                    break;
                case "推荐治疗方案":
                    planDoTipsNum++;
                    var itemStr = inter.InterfaceItemStr;
                    var treatStr = "<div id=\"TreaCont\" class=\"SuspectedContainer\" >";
                    treatStr += "<div class=\"CaptionRect\" >";
                    treatStr += "<div class=\"titleName\" >" + interfaceName + "</div>";
                    treatStr += "<span class=\"fengeLine\">//////////////////</span>";
                    treatStr += "<span class=\"BatchIcon\" onclick=\"SdsTool.showBatchOrder('','" + itemStr + "','order','')\">批</span>";
                    treatStr += "</div>";
                    var treatNum = 0;
                    for (var m = 0; m < itemLen; m++) {
                        var item = interfaceValue[m];
                        var itemType = item.ItemType;
                        var itemName = item.ItemName;
                        if (itemName == "") continue;
                        var itemDesc = item.ItemDesc;
                        var itemId = item.ItemID;
                        var cureId = item.CureId;
                        var treatSource = item.TreatSource;
                        var ruleBasisHtml = item.RuleBasisHtml;
                        var itemChildren = item.children;
                        var sourceFlag = item.SourceFlag;
                        var bookStr = "";
                        var clazz = "";
                        var qcId = item.QCID;
                        var qcIcon = "fa-bookmark";
                        var contraindicationId = item.contraindicationId;
                        var contraindicationName = item.contraindicationName;
                        if (qcId != undefined) {
                            qcIcon = "fa-star";
                        }
                        treatNum++;
                        if (m > 2) {
                            clazz = "more";
                        }
                        var cil = 0;
                        if (ciInfo != undefined) {
                            cil = ciInfo.length;
                        }
                        var status = "已";
                        var clazz1 = "OKIcon";
                        if (cil > 0 && contraindicationId != undefined) {
                            for (var i = 0; i < cil; i++) {
                                var inter = ciInfo[i];
                                if (inter.id !== contraindicationId){
                                    continue;
                                }
                                var CIResult = inter.ciResult;
                                if (CIResult.result === undefined) {
                                    status = "未";
                                    clazz1 = "KaiIcon";
                                }
                            }
                        }

                        treatStr += "<div class=\"" + clazz + "\" id=\"" + itemId + "\" style=\"margin-top: 5px;\"><div class=\"itemTitle\">" +
                            "<i class=\"fa " + qcIcon + "\" aria-hidden=\"true\"></i>" +
                            "<span>" + itemName + "</span>";
                        if (status == '已'){
                            treatStr += "<span class=\"KaiIcon\" onclick=\"SdsTool.showBatchOrder('" + itemName + "','" + itemId + "','order','')\">开</span></div>"
                        }else {
                            treatStr += "</div>"
                        }
                        if (contraindicationId != undefined){
                            treatStr += "<div class=\"itemTitle\"><span style=\"font-size: 11px;font-weight:normal\">&nbsp;&nbsp;&nbsp;相关禁忌症：" + contraindicationName + "</span>" +
                            "<span class=\"" + clazz1 + "\" onclick=\"SdsTool.showBatchCI('','" + contraindicationId + "','')\">" + status + "</span></div>";
                        }
                        if (sourceFlag == 1) {
                            bookStr = "<img src=\"" + httpUrl + "/mediway/sds/img/book.png\" onclick=\"SdsTool.showBook('" + treatSource + "','"+ruleBasisHtml + "')\">";
                        }
                        if (itemDesc != "" && itemDesc != null) {
                            treatStr += "<div class=\"itemDesc\" title=\"" + itemDesc + "\">";
                            if ((itemDesc.split("。").length > 1 && itemDesc.split("。")[1] == "") || itemDesc.split("。").length <= 1) {
                                treatStr += "<span class=\"DisplayDesc\">" + itemDesc + "</span>" + bookStr;
                            } else {
                                treatStr += "<span class=\"DisplayDesc\">" + itemDesc.split("。")[0] + "。</span>" + bookStr + "<span class=\"MoreCont\">展开</span>";
                            }
                            treatStr += "</div>";
                        }
                        // var childCntent = "<div class=\"itemDetail\">";
                        // var childLen = itemChildren.length;
                        // var childNum=0;
                        // for (var j = 0; j < childLen; j++) {
                        //     var treatItemName = itemChildren[j].TreatItemName;
                        //     if (treatItemName == "") continue;
                        //     var treatItemType = itemChildren[j].TreatItemType;
                        //     var frequencyName = "";
                        //     if (treatItemType == "药品") {
                        //         frequencyName = itemChildren[j].FrequencyName;
                        //     }
                        //     var treatItemId = itemChildren[j].ItemID;
                        //     childNum++;
                        //     var clz = "";
                        //     if (childNum > 3) {
                        //         clz = "more";
                        //     }
                        //     childCntent += "<li class=\""+clz+"\">"+treatItemName+"&nbsp;"+frequencyName+ "</li>";
                        //
                        // }
                        // if (childNum > 3) {
                        //     childCntent += " <li class=\"text-center\"><a class=\"btn show-more-btn\">点击加载更多</a></li>";
                        // }
                        // childCntent += "</div>";
                        // if (childNum > 0) {
                        //     treatStr += childCntent;
                        // }
                        treatStr += "</div>";
                    }
                    if (itemLen > 3) {
                        treatStr += " <div class=\"text-center\"><a class=\"btn show-more-btn\">点击加载更多</a></div>";
                    }
                    treatStr += "</div>";
                    if (treatNum > 0) {
                        treatContent = treatStr;
                    }
                    break;
                case "推荐护理处置":
                    planDoTipsNum++;
                    var itemStr = inter.InterfaceItemStr;
                    var nursingStr = "<div id=\"NursCont\" class=\"SuspectedContainer\" >";
                    nursingStr += "<div class=\"CaptionRect\" >";
                    nursingStr += "<div class=\"titleName\" >" + interfaceName + "</div>";
                    nursingStr += "<span class=\"fengeLine\">//////////////////</span>";
                    nursingStr += "<span class=\"BatchIcon\" onclick=\"SdsTool.showBatchOrder('','" + itemStr + "','nursing','')\">批</span>";
                    nursingStr += "</div>";
                    var nursingNum = 0;
                    for (var m = 0; m < itemLen; m++) {
                        var item = interfaceValue[m];
                        var itemType = item.ItemType;
                        var itemName = item.ItemName;
                        if (itemName == "") continue;
                        var itemDesc = item.ItemDesc;
                        var itemId = item.ItemID;
                        var cureId = item.CureId;
                        var treatSource = item.TreatSource;
                        var ruleBasisHtml = item.RuleBasisHtml;
                        var sourceFlag = item.SourceFlag;
                        var bookStr = "";
                        var clazz = "";
                        var qcId = item.QCID;
                        var qcIcon = "fa-bookmark";
                        if (qcId != undefined) {
                            qcIcon = "fa-star";
                        }
                        nursingNum++;
                        if (m > 2) {
                            clazz = "more";
                        }
                        nursingStr += "<div class=\"" + clazz + "\" id=\"" + itemId + "\" style=\"margin-top: 5px;\"><div class=\"itemTitle\" >" +
                            "<i class=\"fa " + qcIcon + "\" aria-hidden=\"true\"></i>" +
                            "<span>" + itemName + "</span>" +
                            "<span class=\"KaiIcon\" onclick=\"SdsTool.showBatchOrder('" + itemName + "','" + itemId + "','nursing','')\">开</span></div>";
                        if (sourceFlag == 1) {
                            bookStr = "<img src=\"" + httpUrl + "/mediway/sds/img/book.png\" onclick=\"SdsTool.showBook('" + treatSource + "','"+ruleBasisHtml + "')\">";
                        }
                        if (itemDesc != "" && itemDesc != null) {
                            nursingStr += "<div class=\"itemDesc\" title=\"" + itemDesc + "\">";
                            if ((itemDesc.split("。").length > 1 && itemDesc.split("。")[1] == "") || itemDesc.split("。").length <= 1) {
                                nursingStr += "<span class=\"DisplayDesc\">" + itemDesc + "</span>" + bookStr;
                            } else {
                                nursingStr += "<span class=\"DisplayDesc\">" + itemDesc.split("。")[0] + "。</span>" + bookStr + "<span class=\"MoreCont\">展开</span>";
                            }
                            nursingStr += "</div>";
                        }
                        nursingStr += "</div>";
                    }
                    if (itemLen > 3) {
                        nursingStr += " <div class=\"text-center\"><a class=\"btn show-more-btn\">点击加载更多</a></div>";
                    }
                    nursingStr += "</div>";
                    if (nursingNum > 0) {
                        nursingContent = nursingStr;
                    }
                    break;
                case "推荐评估量表":
                    planDoTipsNum++;
                    var assessStr = "<div id=\"RatiCont\" class=\"SuspectedContainer\" >";
                    assessStr += "<div class=\"CaptionRect\" >";
                    assessStr += "<div class=\"titleName\" >" + interfaceName + "</div>";
                    assessStr += "<span class=\"fengeLine\">//////////////////</span>";
                    assessStr += "</div>";
                    var evalNum = 0;
                    for (var m = 0; m < itemLen; m++) {
                        var item = interfaceValue[m];
                        var itemType = item.ItemType;
                        var itemName = item.ItemName;
                        if (itemName == "") continue;
                        var itemDesc = item.ItemDesc;
                        var itemId = item.ItemID;
                        var nodeId = item.NodeId;
                        var cureId = item.CureId;
                        var treatSource = item.TreatSource;
                        var ruleBasisHtml = item.RuleBasisHtml;
                        var sourceFlag = item.SourceFlag;
                        var itemDone = item.ItemDone;
                        var bookStr = "";
                        var clazz = "";
                        var qcId = item.QCID;
                        var qcIcon = "fa-bookmark";
                        if (qcId != undefined) {
                            qcIcon = "fa-star";
                        }
                        evalNum++;
                        if (m > 6) {
                            clazz = "more";
                        }
                        assessStr += "<div class=\"" + clazz + "\" id=\"" + itemId + "\" style=\"margin-top: 5px;\">" +
                            "<div class=\"RatingScaleName\" onclick=\"SdsTool.showASMT('" + itemName + "','" + nodeId + "','" + itemId + "','plan')\">" +
                            "<i class=\"fa " + qcIcon + "\" aria-hidden=\"true\"></i>" + itemName +
                            "<img src=\"" + httpUrl + "/mediway/sds/img/book.png\" onclick=\"SdsTool.showBook('" + treatSource + "','"+ruleBasisHtml+"')\"></div>";
                        if (sourceFlag == 1) {
                            bookStr = "<img src=\"" + httpUrl + "/mediway/sds/img/book.png\" onclick=\"SdsTool.showBook('" + treatSource + "','"+ruleBasisHtml+"')\">";
                        }
                        if (itemDesc != "" && itemDesc != null) {
                            assessStr += "<div class=\"itemDesc\" title=\"" + itemDesc + "\">";
                            if ((itemDesc.split("。").length > 1 && itemDesc.split("。")[1] == "") || itemDesc.split("。").length <= 1) {
                                assessStr += "<span class=\"DisplayDesc\">" + itemDesc + "</span>" + bookStr;
                            } else {
                                assessStr += "<span class=\"DisplayDesc\">" + itemDesc.split("。")[0] + "。</span>" + bookStr + "<span class=\"MoreCont\">展开</span>";
                            }
                            assessStr += "</div>";
                        }
                        var score = "未对患者进行此评估";
                        var level = "";
                        var date = "";
                        if (itemDone != 0) {
                            score = item.itemScore;
                            level = item.itemLevel;
                            date = item.itemDate;
                            assessStr += "<div class=\"itemDesc\">";
                            assessStr += "<span class=\"DisplayDesc\">最新评估结果：</span>";
                            assessStr += "</div>";
                            assessStr += "<div class=\"timeline\" >";
                            assessStr += "<div class=\"shijian\">" + score + "分<span style=\"color:#666;margin-left:10px;font-size:12px;\">" + level + "</span><span onclick=\"SdsTool.WriteToHis("+ JSON.stringify(item).replace(/\"/g,"'") +",'推荐评估量表','评估结果')\" class=\"WriteIcon\">写</span><Button class=\"DeleteIcon\">删</Button></div>";
                            assessStr += "<div class=\"shijian\">" + date + "</div>  ";
                            assessStr += "</div>";
                        } else {
                            assessStr += "<div class=\"itemDesc\">";
                            assessStr += "<span class=\"DisplayDesc\">最新评估结果：<span class=\"score\">" + score + "</span></span>";
                            assessStr += "</div>";
                        }
                        assessStr += "</div>";
                    }
                    if (itemLen > 7) {
                        assessStr += " <div class=\"text-center\"><a class=\"btn show-more-btn\">点击加载更多</a></div>";
                    }
                    assessStr += "</div>";
                    if (evalNum > 0) {
                        assessContent = assessStr;
                    }
                    break;
            }
        }
        planDoTips = examContent + labContent + treatContent + nursingContent + assessContent;
        if (planDoTips == "") {
            planDoTips = "<div class=\"fixed-box\">\n" +
                "        <img style=\"margin-top: 150px;\" src=\"" + httpUrl + "/mediway/sds/img/nodataimg.png\">\n" +
                "     </div>"
        }
    }

    /**质控*/
    owner.qcMsg = function (ipqcInfo) {
        qcTips = "";
        qcTipsNum = 0;
        var l = ipqcInfo.length;
        if (l > 0) {
            for (var i = 0; i < l; i++) {
                var inter = ipqcInfo[i];
                var QCDesc = inter.QCDesc;
                var QCMemo = inter.QCMemo;
                var QCSource = inter.QCSource;
                qcTips += "<div id=\"RecomLabExam\" class=\"SuspectedContainer\" >";
                qcTips += "<div id=" + i + " class=\"item\">" +
                    "<div class=\"itemTitle\" >" +
                    "<i class=\"fa fa-bookmark\" aria-hidden=\"true\"></i>" +
                    "<span>" + QCDesc + "</span>" +
                    "<span class=\"KaiIcon\" onclick=\"SdsTool.eliminate(this)\">×</span>" +
                    "<a href=\"javascript:alert('333')\"><i class=\"fa  fa-hand-paper-o\" aria-hidden=\"true\"></i></a></div>";
                qcTips += "<div class=\"itemDesc\"><span>" + QCMemo + "</span></div>";
                qcTips += "<div class=\"itemSource\" title=\"" + QCSource + "\"><div>" + QCSource + "</div></div>";
                qcTips += "</div></div>";
            }
        } else {
            qcTips = "<div class=\"fixed-box\">\n" +
                "        <img style=\"margin-top: 150px;\" src=\"" + httpUrl + "/mediway/sds/img/nodataimg.png\">\n" +
                "     </div>"
        }

        qcTipsNum = l;
        if (qcTipsNum == 0) {
            $(".alarm").text(qcTipsNum).hide();
            $("#WarnNumber").text(qcTipsNum);
            $("#WarnNumber1").text(qcTipsNum);
        } else {
            $(".alarm").text(qcTipsNum).show();
            $("#WarnNumber").text(qcTipsNum);
            $("#WarnNumber1").text(qcTipsNum);
        }
    }

    owner.eliminate = function (obj) {

        var qcInfo;
        var data = currentData;
        var dl = data.length;
        if (dl > 0) {
            for (var i = 0; i < dl; i++) {
                var perData = data[i];
                var type = perData.type;
                if (type == 4) { // 质控项目
                    qcInfo = perData.ipqcInfo;
                }
            }
        }
        var qcDesc = $(obj).prev().text();
        var layer = layui.layer;
        var flag = false;
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        if (qcentity.id == null) {
            layer.msg("当前患者未进入单病种质控！");
            return
        }
        //iframe层
        var iframeSrc = httpUrl + '/api/sdc/eliminate/toAdd?episodeId='
            + params.episodeId  + '&docId=' + params.userCode + '&qcDesc=' + encodeURIComponent(qcDesc) ;
        var index = layer.open({
            id: 'test_layer',
            type: 2,
            title: '<i class="layui-icon">&#xe62a;</i>质控手动纠正',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['30%', '30%'],
            content: iframeSrc

        });
        layui.element.init();
        function receiveQcMessage(event) {
            //取得子页面传回来的值
            var datum = event.data[0];
            if (datum == 'chenggong') {
                // 如果传回close，关闭当前弹窗
                flag = true;

                $(obj).parent().parent().parent().remove();
                layer.close(index);

                if (qcInfo.length > 0) {
                    for (var i = 0; i < qcInfo.length; i++) {
                        for(var key in qcInfo[i]){
                            if (key === 'QCDesc' && qcInfo[i][key] === qcDesc){
                                qcInfo.splice(i,1);
                            }
                        }
                    }
                }
                owner.qcMsg(qcInfo);
                window.removeEventListener('message', receiveQcMessage, false);
            }
        }

        window.addEventListener('message', receiveQcMessage, false);

    }

    /**
     * 禁忌症信息
     */
    owner.CIMsg = function (ciInfo) {
        ciTips = "";
        ciTipsNum = 0;
        var l = ciInfo.length;

        ciTips += "<div id=\"RecomLabExam\" class=\"SuspectedContainer\" >";
        ciTips += "     <div class=\"CaptionRect\" >";
        ciTips += "         <div class=\"titleName\" >禁忌症</div>";
        ciTips += "         <span class=\"fengeLine\">//////////////////</span>";
        // ciTips += "         <span class=\"BatchIcon\" onclick=\"SdsTool.showBatchCI('','"+"1,2"+"','exam')\">批</span>";
        ciTips += "     </div>";
        if (l > 0) {
            for (var i = 0; i < l; i++) {
                var inter = ciInfo[i];
                var CIName = inter.name;
                var CIDesc = inter.info;
                var CIResult = inter.ciResult;
                var CIDetail = inter.ciDetail;
                var status = "未";
                var clazz = "KaiIcon";
                if (CIResult.result != undefined) {
                    status = "已";
                    clazz = "OKIcon";
                }
                ciTips += "     <div class=\"item\" style=\"margin-bottom: 10px;\">"
                ciTips += "         <div class=\"itemTitle\" >";
                ciTips += "             <i class=\"fa fa-bookmark\" aria-hidden=\"true\"></i>";
                ciTips += "             <span>" + CIName + "</span>";
                ciTips += "             <span class=\"" + clazz + "\" onclick=\"SdsTool.showBatchCI('','" + inter.id + "','')\">" + status + "</span>";
                ciTips += "         </div>";
                ciTips += "         <div class=\"itemDesc\"><span>" + CIDesc + "</span></div>";
                for (var j = 0; j < CIDetail.length; j++) {
                    var dtl = CIDetail[j];
                    ciTips += "         <div class=\"timeline\" >";
                    ciTips += "             <div class=\"shijian\">" + dtl.itemName + "<span style=\"color:#666;margin-left:10px;font-size:12px;\"></span></div>";
                    ciTips += "         </div>";
                }
                ciTips += "     </div>";
            }
            ciTips += "</div>";
        } else {
            ciTips = "<div class=\"fixed-box\">\n" +
                "        <img style=\"margin-top: 150px;\" src=\"" + httpUrl + "/mediway/sds/img/nodataimg.png\">\n" +
                "     </div>"
        }
    };


    function f(a,b) {  //排序函数
        return (a - b);  //返回比较参数
    }
    /**
     * DRG费用信息
     */
    owner.DRGMsg = function (drgInfo){
        if(typeof (drgInfo) == "undefined"){//接口出错时
            drgTips = "";
            drgTipsNum = 0;

            var nursingStr = "<div id=\"NursCont\" class=\"SuspectedContainer\" >";
            nursingStr += "<div class=\"CaptionRect\" >";
            nursingStr += "<div class=\"titleName\" >" + "分组信息" + "</div>";
            nursingStr += "<span class=\"fengeLine\">//////////////////</span>";
            nursingStr += "</div>";
            nursingStr += "<div class=\"" + "" + "\" id=\"" + "drgFeeChart" + "\" style=\"margin-top: 5px;width:100%;height:220px;\"><div class=\"itemTitle\" style='color: red;text-align: center'>DRG接口访问出错，请联系管理员</div>";
            nursingStr += "</div>";
            nursingStr += "</div>";
            var assessStr = "<div id=\"RatiCont\" class=\"SuspectedContainer\" >";
            assessStr += "<div class=\"CaptionRect\" >";
            assessStr += "<div class=\"titleName\" >" + "费用情况" + "</div>";
            assessStr += "<span class=\"fengeLine\">//////////////////</span>";
            assessStr += "</div>";
            assessStr += "<div class=\"\" id=\"241\" style=\"margin-top: 5px;\"><div class=\"itemTitle\"><i class=\"fa fa-bookmark\" aria-hidden=\"true\"></i><span></span></div></div>"
            assessStr += "<table id=\"drgItemBlock\" style=\"margin-top: 5px;\"></table>"
            assessStr += "</div>";

            drgTips = assessStr + nursingStr;

            $("#cdss").html(drgTips);
        }else if(typeof(drgInfo.GROUP_DESC) == "undefined"){
            drgTips = "";
            drgTipsNum = 0;

            var nursingStr = "<div id=\"NursCont\" class=\"SuspectedContainer\" >";
            nursingStr += "<div class=\"CaptionRect\" >";
            nursingStr += "<div class=\"titleName\" >" + "分组信息" + "</div>";
            nursingStr += "<span class=\"fengeLine\">//////////////////</span>";
            nursingStr += "</div>";
            nursingStr += "<div class=\"" + "" + "\" id=\"" + "drgFeeChart" + "\" style=\"margin-top: 5px;width:100%;height:220px;\"><div class=\"itemTitle\" style='color: red;text-align: center'>该患者没有费用信息</div>";
            nursingStr += "</div>";
            nursingStr += "</div>";
            var assessStr = "<div id=\"RatiCont\" class=\"SuspectedContainer\" >";
            assessStr += "<div class=\"CaptionRect\" >";
            assessStr += "<div class=\"titleName\" >" + "费用情况" + "</div>";
            assessStr += "<span class=\"fengeLine\">//////////////////</span>";
            assessStr += "</div>";
            assessStr += "<div class=\"\" id=\"241\" style=\"margin-top: 5px;\"><div class=\"itemTitle\"><i class=\"fa fa-bookmark\" aria-hidden=\"true\"></i><span></span></div></div>"
            assessStr += "<table id=\"drgItemBlock\" style=\"margin-top: 5px;\"></table>"
            assessStr += "</div>";

            drgTips = assessStr + nursingStr;

            $("#cdss").html(drgTips);
        } else {
            drgTips = "";
            drgTipsNum = 0;

            var nursingStr = "<div id=\"NursCont\" class=\"SuspectedContainer\" >";
            nursingStr += "<div class=\"CaptionRect\" >";
            nursingStr += "<div class=\"titleName\" >" + "分组信息" + "</div>";
            nursingStr += "<span class=\"fengeLine\">//////////////////</span>";
            nursingStr += "</div>";
            if (!drgInfo.IN_GROUP){
                nursingStr += "<div class=\"\" id=\"242\" style=\"margin-top: 5px;\"><div class=\"itemTitle\"><i class=\"fa fa-bookmark\" aria-hidden=\"true\"></i><span>该病例未入组</span></div></div>"
                nursingStr += "<div class=\"\" id=\"243\" style=\"margin-top: 5px;\"><div class=\"itemTitle\"><i class=\"fa fa-bookmark\" aria-hidden=\"true\"></i><span>未入组原因-"+drgInfo.NOT_IN_REASON+"</span></div></div>"
            }else {
                //nursingStr += "<table id=\"drgItemBlock\" style=\"margin-top: 5px;\"></table>"
                nursingStr += "<div class=\"\" id=\"242\" style=\"margin-top: 5px;\"><div class=\"itemTitle\"><i class=\"fa fa-bookmark\" aria-hidden=\"true\"></i><span>("+drgInfo.GROUP_CODE+")"+drgInfo.GROUP_DESC+"</span></div></div>"
                nursingStr += "<div class='drgmi-ZGlwbWk'>\n" +
                    "    <style>\n" +
                    "        .drgmi-ZGlwbWk table{border-collapse: collapse;font-size:14px;width:100%;margin:0 10px 10px 10px;}\n" +
                    "        .drgmi-ZGlwbWk table td {padding: 0 5px;border: 1px solid #DDDDDD !important;}\n" +
                    "    </style>\n" +
                    "    <div style='padding-right:20px;'>\n" +
                    "        <table>\n" +
                    "            <tbody>\n" +
                    "            <tr style='height:35px'>\n" +
                    "                <td>当前费用："+drgInfo.TOTAL_EXPENSE+"</td>\n" +
                    "            </tr>\n" +
                    "            <tr style='height:35px'>\n" +
                    "                <td>支付标准："+drgInfo.STD_FEE+"</td>\n" +
                    "            </tr>\n" +
                    "            <tr style='height:35px'>\n" +
                    "                <td>均费标准："+drgInfo.AVG_FEE+"</td>\n" +
                    "            </tr>\n" +
                    "            <tr style='height:35px'>\n" +
                    "                <td>病组权重："+drgInfo.WEIGHT+"</td>\n" +
                    "            </tr>\n" +
                    "            <tr style='height:35px'>\n" +
                    "                <td>病组费率："+drgInfo.FIGURE+"</td>\n" +
                    "            </tr>\n" +
                    "            <tr style='height:35px'>\n" +
                    "                <td>病例权重："+drgInfo.WEIGHT+"</td>\n" +
                    "            </tr>\n" +
                    "            <tr style='height:35px'>\n" +
                    "                <td>\n"
                if (drgInfo.RATIO_DESC=="高倍率"){
                    nursingStr += "高低倍率：<span style='min-width:18px; height:18px;background-color:#ee0f0f;line-height:18px; padding: 2px 5px; color:#FFF; text-align:center;font-size:12px'>"+drgInfo.RATIO_DESC+"</span> "+drgInfo.FEE_RATIO+"\n"
                }else {
                    nursingStr += "高低倍率：<span style='min-width:18px; height:18px;background-color:#339eff;line-height:18px; padding: 2px 5px; color:#FFF; text-align:center;font-size:12px'>"+drgInfo.RATIO_DESC+"</span> "+drgInfo.FEE_RATIO+"\n"
                }
                nursingStr += "</td>\n" +
                    "            </tr>\n" +
                    "            <tr style='height:35px'>\n" +
                    "                <td>\n"
                if (drgInfo.PROFIT>=0){
                    nursingStr +="盈亏：<span style='width:20px; height:20px;background-color:#5DB42F; border-radius:16px;font-weight: bold; line-height:20px; display:inline-block; color:#FFF; text-align:center;font-size:14px'>√</span> <span style='color:5DB42F'>"+drgInfo.PROFIT+"</span>\n"
                }else {
                    nursingStr +="盈亏：<span style='width:20px; height:20px;background-color:#F25757; border-radius:16px;font-weight: bold; line-height:20px; display:inline-block; color:#FFF; text-align:center;font-size:14px'>i</span> <span style='color:#F25757'>"+drgInfo.PROFIT+"</span>\n"

                }

                nursingStr +=" </td>\n" +
                    "            </tr>\n" +
                    "            </tbody>\n" +
                    "        </table>\n" +
                    "    </div>\n" +
                    "</div>"

            }

            nursingStr += "</div>";
            nursingStr += "</div>";
            var assessStr = "<div id=\"RatiCont\" class=\"SuspectedContainer\" >";
            assessStr += "<div class=\"CaptionRect\" >";
            assessStr += "<div class=\"titleName\" >" + "费用情况" + "</div>";
            assessStr += "<span class=\"fengeLine\">//////////////////</span>";
            assessStr += "</div>";
            assessStr += "<div class=\"\" id=\"241\" style=\"margin-top: 5px;\"><div class=\"itemTitle\"><i class=\"fa fa-bookmark\" aria-hidden=\"true\"></i><span>费用倍率评估-"+drgInfo.RATIO_DESC+"</span></div></div>";
            assessStr += "<div class=\"" + "" + "\" id=\"" + "drgFeeChart" + "\" style=\"margin-top: 5px;width:100%;height:220px;\"><div class=\"itemTitle\" >" +
                "</div>"
            assessStr += "</div>";
            assessStr += "</div>";

            drgTips = assessStr + nursingStr;

            $("#cdss").html(drgTips);
            $('#drgItemBlock').datagrid({
                data: [
                    {code: '支付标准', name: drgInfo.STD_FEE},
                    {code: '支付金额', name: drgInfo.PAY_FEE},
                    {code: '均费标准', name: drgInfo.AVG_FEE},
                    {code: '病组权重', name: drgInfo.WEIGHT},
                    {code: '病组费率', name: drgInfo.FIGURE},
                    {code: '高低倍率', name: drgInfo.FEE_RATIO}
                ],
                columns:[[
                    {field:'code',width:120,display:'none'},
                    {field:'name',width:130,display:'none'}
                ]],
                height: 195
            })
            var myChart = echarts.init(document.getElementById('drgFeeChart'));
            var chartCenter = "";
            //坐标轴区间：开始值和最大值定义
            var min,max;
            min = drgInfo.LOW>1000?drgInfo.LOW-1000:0;//最小值：总费用和几个指标最小的一个减去一千，如果小于0则取0
            max = drgInfo.HIGH+1000;//最大值：总费用和几个指标值最大的+1000

            //仪表盘数据
            var guageData=[
                {
                    value: drgInfo.LOW,
                    detail: {
                        offsetCenter: ['-60%', '60%']
                    }
                },
                {
                    value: drgInfo.HIGH,
                    detail: {
                        offsetCenter: ['60%', '60%']
                    }
                },
                {
                    value: drgInfo.TOTAL_EXPENSE,
                    detail: {
                        offsetCenter: ['0%', '-10%']
                    }
                }
            ];
            // 效果1
            var option = {
                series: [
                    {
                        type: "gauge",
                        center: ["50%", "55%"],
                        radius: "85%",
                        startAngle: 200,        // 仪表盘起始角度,默认 225。圆心 正右手侧为0度，正上方为90度，正左手侧为180度。
                        endAngle: -20,          // 仪表盘结束角度,默认 -45
                        min: min,
                        max: max,
                        splitNumber: 4, // 分割线个数（除原点外）,
                        anchor: {
                            show: true,
                            showAbove: true,
                            size: 18,
                            itemStyle: {
                                color: 'none'
                            }
                        },
                        pointer: {
                            icon: 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z',
                            length: '12%',
                            width: 10,
                            offsetCenter: [0, '-75%'],
                        },
                        // 进度条
                        progress: {
                            show: true,
                            width: 10,
                            roundCap: true, //圆角
                        },
                        // 坐标轴线
                        axisLine: {
                            lineStyle: {
                                width: 10
                            }
                        },
                        // 刻度标签(0/25/50/75/100)
                        axisLabel: {
                            show: false,
                            distance: -15,
                            color: "#000000",
                            interval:0,
                            rotate: 'tangential',
                            fontSize: 8
                        },
                        // 刻度
                        axisTick: {
                            show: false,
                            distance: -22,
                            interval:0,
                            splitNumber: 1,
                            lineStyle: {
                                width: 1,
                                color: "#325BF1",
                            },
                        },
                        // 分隔线
                        splitLine: {
                            show: false,
                            distance: -27,
                            length: 5,
                            lineStyle: {
                                width: 1,
                                color: "#325BF1",
                            },
                        },
                        detail: {
                            valueAnimation: true,
                            lineHeight: 20,
                            borderRadius: 8,
                            offsetCenter: [0, "-10%"],
                            color: "inherit",
                            backgroundColor: 'none',
                            fontSize: 12,
                            formatter:function(value){
                                if(value ===drgInfo.HIGH){
                                    return 'DRG极高:'+Math.round(value);
                                }else if(value ===drgInfo.LOW){
                                    return 'DRG极低:'+Math.round(value);
                                // }else if(value ===ciInfo.costFull){
                                //     return '满分值:'+Math.round(value);
                                // }else if(value ===ciInfo.costMid){
                                //     return '中位值:'+Math.round(value);
                                // }else if(value ===ciInfo.costTarget){
                                //     return '目标值:'+Math.round(value);
                                }else if(value ===drgInfo.TOTAL_EXPENSE){
                                    return '当前费用:'+Math.round(value)+"\n"+chartCenter;
                                }
                            }
                        },
                        data: guageData,
                    },
                ],
            };
            myChart.setOption(option);
            $('#drgFeeBlock').datagrid({
                data: [
                    {code: '医疗总费用', name: drgInfo.TOTAL_EXPENSE}
                ],
                columns:[[
                    {field:'code',width:120,display:'none'},
                    {field:'name',width:130,display:'none'}
                ]],
                height: 58
            })
            $(".datagrid-header").hide();//隐藏表头
        }
    }

    function MaskIt(obj, tips){
        var hoverDiv = "<div class=\"divMask\"><p>" + tips + "</p></div>";
        $(obj).wrap("<div class=\"position:relative;\"></div>");
        $(obj).before(hoverDiv);
        $(obj).data("mask",true);
    }
    function UnMaskIt(obj){
        if($(obj).data("mask")==true){
            $(obj).parent().find(".divMask").remove();
            $(obj).unwrap();
            $(obj).data("mask",false);
        }
        $(obj).data("mask",false);
    }

    /**
     * 清空重置部分对象内容
     */
    function clearArea(){
        $(".alarm").text('').hide();
        $("#WarnNumber").text('0');
        $("#WarnNumber1").text('0');
        $("#cdssStatus").hide();
        $("#cdssStatus1").hide();
        $("#cdssStatusMsg").text('').hide();
        qcentity = {};
        $("#entityName").text('');
    }

    /**
     * 保存操作日志
     * @param actionType
     */
    function saveLog(actionType){
        if (qcentity.id == null) {
            return
        }
        $.ajax({
            url: httpUrl + "/api/sdstool/saveLog",
            data: {"actionType":actionType, "modifyUserId": params.userCode, "modifyUserName": params.userName, "episodeId": params.episodeId, "qcentityId": qcentity.id, "locId": params.deptCode, t: new Date().getTime()},
            async: true
        });
    }

    /**
     * 组装提示内容
     * @param data 当前数据
     *
     **/
    owner.loadTips = function () {
        planDoTips = qcTips = ciTips = "<div class=\"fixed-box\">\n<img style=\"margin-top: 150px;\" src=\"" + httpUrl + "/mediway/sds/img/nodataimg.png\">\n</div>";
        inOutTipNum = qcTipsNum = 0;
        var data = currentData;
        var dl = data.length;
        if (dl > 0) {
            for (var i = 0; i < dl; i++) {
                var perData = data[i];
                var type = perData.type;
                if (type == 1) { // 入组提示
                    owner.inMsg(perData);
                } else if (type == 2) { // 出组提示
                    owner.outMsg(perData);
                } else if (type == 3) { // CDSS诊疗辅助
                    if (perData.status != 'success') {
                        $("#cdssStatus").show();
                        $("#cdssStatus1").show();
                        $("#cdssStatusMsg").text("CDSS服务接口异常，请联系产品支持人员处理！").show();
                    } else {
                        $("#cdssStatus").hide();
                        $("#cdssStatus1").hide();
                        $("#cdssStatusMsg").text("").hide();
                    }
                    var ciInfo;
                    for (var j = 0; j < dl; j++) {
                        var proData = data[j];
                        var proType = proData.type;
                        if (proType == 5) {
                            ciInfo = proData.ciInfo;
                        }
                    }
                    cdssInfo=perData.cdssInfo;
                    owner.treatMsg(perData.cdssInfo,ciInfo);
                } else if (type == 4) { // 质控项目
                    owner.qcMsg(perData.ipqcInfo);
                } else if (type == 5) { // 禁忌症
                    owner.CIMsg(perData.ciInfo);
                } else if (type == 6) { // 病种变更
                    owner.outMsg(perData);
                }else if (type == 7) { // 手动出组
                    clearArea();
                    $("#entityName").text("该病人已出组");
                }else if (type == 8) { // 病种禁用
                    clearArea();
                    $("#entityName").text("病种未启用");
                } else if (type == 9) {
                    qcentity.id = perData.entityId;
                    qcentity.name = perData.entityDesc;
                    $("#entityName").text(qcentity.name);
                } else if(type == 0) {
                    // 患者死亡状态禁止操作（遮罩）
                    if (perData.isDeath) {
                        MaskIt($('#cdss'), "患者已死亡，系统停止诊疗推荐和过程质控！");
                    } else {
                        UnMaskIt($('#cdss'));
                    }
                }else if(type ==13){
                    //质控条目弹框
                    var qcBoxConfig=perData.qcBoxConfig;
                    var needQcBox=perData.needQcBox;
                    var entityDesc=perData.entityDesc;
                    var nl = needQcBox.length;
                    if (nl > 0) {
                        var dbzTitleInfoHtml = "<br>";
                        $.each(needQcBox,function(i,v){
                            dbzTitleInfoHtml += "<span style='color:#ff7e00;background-color:#fff3dd;border: 1px solid #f7d199;margin-left:10px;'>"+(i+1)+"："+v+"</span><br><br>";
                        });
                        if(qcBoxConfig==0){//每次切换患者
                            if(dbzTitleInfoHtml!==""){
                                dbzTitleInfoHtml = dbzTitleInfoHtml.substring(0,dbzTitleInfoHtml.length-4);
                                $("#dbzTitleInfoHtml").html(dbzTitleInfoHtml);
                                owner.opendbzTitle(dbzTitleInfoHtml);
                            }
                        }else if(qcBoxConfig==1){//每一天第一次打开该患者弹框
                            // 检查是否已经显示过弹窗
                            if (localStorage.getItem('popupShown') !== 'true') {
                                if(dbzTitleInfoHtml!==""){
                                    dbzTitleInfoHtml = dbzTitleInfoHtml.substring(0,dbzTitleInfoHtml.length-4);
                                    $("#dbzTitleInfoHtml").html(dbzTitleInfoHtml);
                                    owner.opendbzTitle(dbzTitleInfoHtml);
                                }
                                // 设置弹窗已显示过，下次进入页面时不会再弹出
                                localStorage.setItem('popupShown', 'true');
                            }
                        }
                    }
                } else {
                    /* owner.treatMsg(perData.cdssInfo);
                     owner.qcMsg(perData.ipqcInfo);
                     owner.CIMsg(perData.ciInfo);*/
                }
            }
        } else {
            clearArea();
            $("#entityName").text("未入组任何病种");
            UnMaskIt($('#cdss'));
        }
        $("#cdss").html(planDoTips);
        $(".cdssdiv,.qcdiv,.cidiv,.drgdiv").removeClass('menuSelection');
        $(".cdssdiv").addClass("menuSelection");
        owner.bindOnClick();
        owner.sdsNum = inOutTipNum===0?qcTipsNum:inOutTipNum;
        if (!isShowIcon) {
            DHCDSSNavConfig.changeNavWarnNum("sds",owner.sdsNum);
        }
    };

    owner.opendbzTitle=function(dbzTitleInfoHtml){
        var titleIndex = layer.open({
            style: "padding:10px;",
            type: 1,
            title: ['单病种'+'质控提示消息'],//质控提示消息
            area: ['400px', 'auto'], //宽高
            fix: false, //不固定
            maxmin: false,
            skin: 'layer-ext-hisui',
            zIndex: 1100,
            btn: ['已知悉'],//已知悉
            btnAlign: 'c',
            yes:function(index, layero){
                layer.close(titleIndex);
            },
            content: dbzTitleInfoHtml+"<br>"
        });
    }

    /**
     * 展开菜单
     * @param type
     */
    owner.openMenu = function (type) {
        if (type == 1) {
            $("#smallMenuDiv").hide();
            $("#menudiv").show();
        } else {
            $("#smallMenuDiv").show();
            $("#menudiv").hide();
        }
    };

    /**
     * 关闭弹窗
     */
    owner.minimize = function () {
        $("#app-cdss").hide();
        $("#toolbar").show();
        // 关闭弹窗时再次重新获取后台推荐
        //owner.analysis();
        // owner.loadTips();
        if (!isShowIcon) {
            DHCDSSNavConfig.initNavStatus();
        }
    };

    /** 打开SDS窗口
     * @param
     **/
    owner.openSdsWindow = function () {
        var layer = layui.layer;
        if (params.episodeId == "") {
            layer.tips("请先选择患者的就诊记录！","#toolbar",{tips: [1, '#3595CC'], time: 2000});
            return
        }
        saveLog("open");
        // 默认显示诊疗辅助内容
        owner.CountClick("TreatMenu");
        $("#app-cdss").show();
        $("#toolbar").hide();
    };

    /**
     * 标题点击
     */
    owner.CountClick = function (OperType) {
        $("#cdss").show();
        $("#batch").hide();
        $(".cdssdiv,.qcdiv,.cidiv,.drgdiv").removeClass('menuSelection');
        if (OperType == 'TreatMenu') {
            $("#cdss").html(planDoTips);
            $(".cdssdiv").addClass("menuSelection");
            // 保存日志
            saveLog("treat");
        } else if (OperType == 'WarnMenu') {
            $("#cdss").html(qcTips);
            $(".qcdiv").addClass("menuSelection");
            // 保存日志
            saveLog("qc");
        } else if (OperType == 'DRGMenu') {
            owner.reloadDRGInfo();
            $(".drgdiv").addClass("menuSelection");
            // 保存日志
            saveLog("qc");
        }
        // else {
        //     owner.reloadCIInfo();
        //     $("#cdss").html(ciTips);
        //     $(".cidiv").addClass("menuSelection");
        //     // 保存日志
        //     saveLog("ci");
        // }

        owner.bindOnClick();
    };

    owner.bindOnClick = function() {
        // 点击加载更多
        $('.MoreCont').unbind("click");
        $('.MoreCont').click(function () {
            var itemDesc = $(this).parent().attr("title");
            if ($(this).text() == "展开") {
                $(this).text("收起");
                $(this).siblings('.DisplayDesc').text(itemDesc);
            } else {
                $(this).text("展开");
                $(this).siblings('.DisplayDesc').text(itemDesc.split('。')[0] + "。");
            }
        });
        // 点击加载更多
        $('.show-more-btn').unbind("click");
        $('.show-more-btn').click(function () {
            if ($(this).text() == "点击加载更多") {
                $(this).text("点击收起");
                $(this).parent().siblings('.more').show();
            } else {
                $(this).text("点击加载更多");
                $(this).parent().siblings('.more').hide();
            }
        });
    }

    /** 患者信息弹窗
     * @param
     **/
    owner.showPatientInfo = function () {
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        //iframe层
        var iframeSrc = httpUrl + '/api/sdstool/patientInfo';
        var index = layer.open({
            id: 'lay_patient',
            type: 2,
            title: '<i class="layui-icon" >&#xe66f;</i> 患者信息',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['80%', '80%'],
            content: iframeSrc
        });
        layui.element.init();
    };

    /** CDSS弹窗
     * @param
     **/
    owner.showCDSS = function () {
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        //iframe层
        var iframeSrc = config.CDSSServer + "/api/preview/csp/rolesourceview.html?cureId=17892";
		if ('undefined'!==typeof websys_getMWToken){
			iFrameSrc += "&MWToken="+websys_getMWToken()
		}
        var index = layer.open({
            id: 'lay_cdss',
            type: 2,
            title: '<i class="layui-icon" >&#xe66f;</i> 患者信息',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['80%', '80%'],
            content: iframeSrc
        });
        layui.element.init();
    };

    /** 知识搜索弹窗
     * @param
     **/
    owner.showSearch = function () {
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        //iframe层
        var iframeSrc = 'http://10.1.20.118:8081/api/vtesearchknowledge?keyWords=';
        var index = layer.open({
            id: 'lay_search',
            type: 2,
            title: '<i class="layui-icon" >&#xe615;</i> 知识搜索',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['80%', '80%'],
            content: iframeSrc
        });
        layui.element.init();
    };

    /**
     * 手动出组
     * @param
     **/
    owner.outofGroup = function (){
        var layer = layui.layer;
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        if (qcentity.id == null) {
            layer.msg("当前患者未进入单病种质控！");
            return
        }
        //iframe层
        var iframeSrc = httpUrl + '/api/sdstool/outOfGroup?modifyUserId=' + params.userCode + '&modifyUserName=' + encodeURIComponent(params.userName) + '&patientId=' + params.episodeId + '&entityId=' + qcentity.id;
        var index = layer.open({
            id: 'lay_stage',
            type: 2,
            title: '<i class="layui-icon">&#xe62a;</i> 手动出组单病种过程质控',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['30%', '30%'],
            content: iframeSrc
        });
        layui.element.init();
        //监听子页面的postMessage
        function receiveCIMessage(event) {
            //取得子页面传回来的值
            if (event.data == "close") {
                // 如果传回close，关闭当前弹窗
                layer.close(index);
                owner.reload();
                window.removeEventListener('message', receiveCIMessage, false);
            }
        }

        window.addEventListener('message', receiveCIMessage, false);
    };

    /**
     * 填报信息
     * @param
     */
    // owner.GetMrListIfo = function (episodeId) {
    //     console.log(episodeId)
    //     var mrlistInfo;
    //     var ajax = new $ax("/sds/sdsqcincase/getMrListInfo", function (data) {
    //         mrlistInfo = data;
    //     }, function () {
    //     });
    //     ajax.setData({"episodeId": episodeId});
    //     ajax.start();
    //     var title = '预填报页面';
    //     var index = Sys.open_c(title, '/sds/sdsqcformshow/'+episodeId, null, function () {});
    //     this.layerIndex = index;
    // }

    /**
     * 表单填报页面弹出窗
     * @param
     **/
    owner.showForm = function () {
        var layer = layui.layer;
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        if (qcentity.id == null) {
            layer.msg("当前患者未进入单病种质控！");
            return
        }
        //iframe层
        var iframeSrc = httpUrl + '/api/sdstool/showForm?modifyUserId=' + params.userCode + '&modifyUserName=' + encodeURIComponent(params.userName) + '&patientId=' + params.episodeId + '&entityId=' + qcentity.id;
        var index = layer.open({
            id: 'lay_form',
            type: 2,
            title: '<i class="layui-icon">&#xe62a;</i> 预填报项目',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['80%', '80%'],
            content: iframeSrc + '&t='+new Date().getTime()
        });
        layui.element.init();
    };

    /**
     * 方案详细情况
     * @param
     **/
    owner.showDetail = function () {
        var layer = layui.layer;
        layer.config({
            extend: 'myskin/style.css', //同样需要先加载新皮肤
            debug: true
        });
        if (qcentity.id == null) {
            layer.msg("当前患者未进入单病种质控！");
            return
        }
        //iframe层
        var iframeSrc = httpUrl + '/api/sdstool/showTreatDetail?patientId=' + params.episodeId + '&entityId=' + qcentity.id;
        var index = layer.open({
            id: 'lay_stage',
            type: 2,
            title: '<i class="layui-icon">&#xe62a;</i> 诊疗推荐项目完成一览',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['60%', '60%'],
            content: iframeSrc + '&t='+new Date().getTime()
        });
        layui.element.init();
    }



    /**
     * 禁忌症处理
     * @param
     **/
    owner.showBatchCI = function (desc, itemStr, planType) {
        var layer = layui.layer;
        var CIList;
        // 获取禁忌症条目及触发信息
        $.ajax({
            url: httpUrl + "/api/sdstool/getCIInfo",
            data: {"itemStr": itemStr, "patientId": params.episodeId, t:new Date().getTime()},
            async: false,
            success: function (res) {
                CIList = res;
            }
        });

        var template = document.getElementById('ci-temp');
        var cdss = document.getElementById('cdss');
        var batch = document.getElementById('batch');
        var tempClone;
        if (document.createElement("template").content) {
            tempClone = template.content.cloneNode(true);
        } else {
            tempClone = document.createElement("div");
            tempClone.innerHTML=template.innerHTML;
        }
        var ci = tempClone.querySelector('#ciItems');
        var title = ci.querySelector('.standardWord');
        var items = ci.querySelector('.standardDesc');
        var item = items.querySelector('.hisui-checkbox');
        var button = tempClone.querySelector('#batchConfirm');
        button.setAttribute("itemType", "CI");

        var l = CIList.length;
        if (l > 0) {
            ci.innerHTML = "";
            var itemStr = "";
            for (var i = 0; i < l; i++) {
                var ciinfo = CIList[i].CIInfo;
                var ciItems = CIList[i].CIItems;
                var ciDtls = CIList[i].CIDtls;
                var itemObjs = CIList[i].ItemObjs;
                var ciDtlArr = ciDtls.split("#");

                title.innerHTML = (i + 1 + ".") + ciinfo.name;
                items.innerHTML = "";
                var options = "";
                for (var j = 0; j < ciItems.length; j++) {
                    var itemObj = ciItems[j];
                    var checkFlag = "";
                    var manualType = "";
                    if (ciDtlArr.indexOf(itemObj.id + "") > 0) {
                        checkFlag = "checked";
                        var itemArr = itemObjs[itemObj.id].split("^");
                        var itemType = itemArr[0];
                        var itemFrom = itemArr[1];
                        if (itemType != 1) {
                            manualType = "    <img style=\"width:14px\" src=\"" + httpUrl + "/mediway/sds/img/auto.png\" keywords=\"" + itemFrom + "\" alt=\"A\">\n";
                        } else {
                            manualType = "    <img style=\"width:14px\" src=\"" + httpUrl + "/mediway/sds/img/manual.png\" keywords=\"" + itemFrom + "\" alt=\"M\">\n";
                        }
                    }
                    options += "<div style=\"width:100%; font-size: 12px;display: inline-block;\">\n";
                    options += "    <input class=\"hisui-checkbox\" type=\"checkbox\" name=\"" + ciinfo.id + "\" id=\"" + itemObj.id + "\" " + checkFlag + ">" + itemObj.itemName + "\n";
                    options += manualType;
                    options += "</div>\n";
                }
                // 不算上系统自动匹配的
                var manualCiDtls = '#';
                for (var j = 0; j < ciDtlArr.length; j++) {
                    if (!ciDtlArr[j]) {
                        continue;
                    }
                    var itemList = itemObjs[ciDtlArr[j]].split("^");
                    if (itemList[0] != 0) {
                        manualCiDtls += ciDtlArr[j] + '#';
                    }
                }
                items.setAttribute("manualCiDtls", manualCiDtls);
                items.setAttribute("ciDtls", ciDtls);
                items.setAttribute("ciId", ciinfo.id);
                items.innerHTML = options;
                itemStr += (title.outerHTML + items.outerHTML);
            }
            ci.innerHTML = itemStr;
            batch.innerHTML = "";
            if (document.createElement("template").content) {
                batch.append(tempClone);
            } else {
                $(batch).append(tempClone.innerHTML);
            }
            $.parser.parse(batch);//解析checkbox
            var indexItem = null;
            $("#batch img").hover(function () {
                indexItem = layer.tips(this.getAttribute("keywords"), this, {
                    tips: 3,
                    area: ['250px', 'auto'],
                    time: 5000
                });
            }, function () {
                layer.close(indexItem);
            });
        } else {
            batch.append("<div>未找到禁忌症维护信息！</div>");
        }
        // 处理内容显示，cdss内容隐藏
        $(batch).show();
        $(cdss).hide();

    }

    /**
     * 批处理返回按钮事件
     */
    owner.sendMsg = function () {
        $("#batch").hide();
        $("#cdss").show();
        owner.bindOnClick();
    }

    /**
     * 批处理返回按钮事件
     */
    owner.getSelected = function (obj) {
        var itemType = $(obj).attr("itemType");

        function saveCI() {
            // 获取选中数据
            var ciSelectObj = {};
            var ciModifyObj = {};

            $("#batch .standardDesc").each(function () {
                var ciId = $(this).attr("ciId");

                ciSelectObj[ciId] = "";
                $("input[name=" + ciId + "][type='checkbox']:checked").each(function () {
                    var id = $(this).attr("id");
                    ciSelectObj[ciId] = ciSelectObj[ciId] + id + "#";
                });

                var ciDtls = $(this).attr("ciDtls");
                var oldIdArr = ciDtls.split("#");
                var manualCiDtls = $(this).attr("manualCiDtls");
                var manualOldIdArr = manualCiDtls.split("#");
                var selectIdArr = ciSelectObj[ciId].split("#");
                var modifyList = [];

                for (var i = 0; i < selectIdArr.length; i++) {
                    if (manualOldIdArr.indexOf(selectIdArr[i]) === -1) {
                        var itemId = selectIdArr[i];
                        modifyList.push({"itemId": itemId, "operation": 1}); //被选中
                    }
                }

                for (var i = 0; i < oldIdArr.length; i++) {
                    if (selectIdArr.indexOf(oldIdArr[i]) === -1) {
                        var itemId = oldIdArr[i];
                        modifyList.push({"itemId": itemId, "operation": 0}); //被剔除
                    }
                }

                ciModifyObj[ciId] = modifyList;
            });

            var X = $("#app-cdss")[0].offsetLeft + 100;  //获取窗口x坐标
            var Y = $("#app-cdss")[0].offsetTop + 100; //获取窗口y坐标

            var map = {};
            map.episodeId = params.episodeId;
            map.locId = params.deptCode;
            map.qcentityId = qcentity.id;
            map.modifyUserId = params.userCode;
            map.modifyUserName = params.userName;
            map.ciSelectObj = JSON.stringify(ciSelectObj);
            map.ciModifyObj = JSON.stringify(ciModifyObj);
            // 获取禁忌症条目及触发信息
            $.ajax({
                url: httpUrl + "/api/sdstool/saveCIInfo",
                data: map,
                async: false,
                success: function (res) {
                    if (res.code == 200) {
                        //提示层
                        layer.msg('保存成功！',{offset: [Y, X]}, function(){
                            owner.reloadTreatCiInfo();
                            // owner.CountClick("CIMenu");
                            $("#cdss").html(planDoTips);
                            console.log(ciSelectObj)
                            console.log(ciModifyObj)
                            //owner.showBatchOrder('','','order',ciModifyObj)
                            $(".cidiv").addClass("menuSelection");
                            $("#cdss").show();
                            $("#batch").hide();
                            owner.bindOnClick();
                        });
                    } else {
                        //提示层
                        layer.msg('保存失败！');
                    }
                }
            });
        }

        function saveOrder() {
            var orderIds = "";
            $("#ciItems .standardDesc input[type='checkbox']:checked").each(function () {
                var id = $(this).attr("id");
                orderIds += id + "#";
            });

            var X = $("#app-cdss")[0].offsetLeft + 100;  //获取窗口x坐标
            var Y = $("#app-cdss")[0].offsetTop + 100; //获取窗口y坐标

            if (orderIds == "") {
                layer.msg("请勾选医嘱", {offset: [Y, X], anim: 6});
            } else {
                var map = {};
                map.orderIds = orderIds;
                map.episodeId = params.episodeId;
                map.locId = params.deptCode;
                map.qcentityId = qcentity.id;
                map.modifyUserId = params.userCode;
                map.modifyUserName = params.userName;
                $.ajax({
                    url: httpUrl + "/api/sdstool/addOrderToHis",
                    data: map,
                    async: false,
                    dataType: 'json',
                    success: function (res) {
                        if (res == "0") {
                            //提示层
                            layer.msg('插入医嘱成功,请打开医嘱录入界面审核!',{offset: [Y, X-100]}, function(){
                                // owner.reloadCIInfo();
                                // owner.CountClick("TreatMenu");
                                $("#cdss").html(planDoTips);
                                $(".cdssdiv").addClass("menuSelection");
                                $("#cdss").show();
                                $("#batch").hide();
                                owner.bindOnClick();
                            });
                        } else {
                            //提示层
                            layer.msg('保存失败！');
                        }
                    }
                });
            }
        }

        if (itemType == "CI") {
            saveCI();
        } else {
            saveOrder();
        }
    }

    /**
     * 禁忌症弹出层
     * @param
     **/
    owner.showCI = function (desc, param, planType) {
        var layer = layui.layer;
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        if (qcentity.id == null) {
            layer.msg("当前患者未进入单病种质控！");
            return
        }
        //iframe层
        var iframeSrc = httpUrl + '/api/sdstool/showCI?modifyUserId=' + params.userCode + '&modifyUserName=' + encodeURIComponent(params.userName) + '&patientId=' + params.episodeId + '&entityId=' + qcentity.id;
        var index = layer.open({
            id: 'lay_ci',
            type: 2,
            title: '<i class="layui-icon">&#xe62a;</i> 禁忌症',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['80%', '80%'],
            closeBtn: false,
            content: iframeSrc + '&t='+new Date().getTime()
        });
        layui.element.init();

        //监听子页面的postMessage
        function receiveCIMessage(event) {
            //取得子页面传回来的值
            if (event.data == "close") {
                // 如果传回close，关闭当前弹窗
                layer.close(index);
                window.removeEventListener('message', receiveCIMessage, false);
            }
            if (event.data == "save") {
                // 后台重新判断质控内容
                owner.analysis();
                setTimeout(function () {
                    layer.close(index);
                }, 1000);
            }
        }

        window.addEventListener('message', receiveCIMessage, false);
    };

    /** 评估量表弹出层
     * @param
     **/
    owner.showASMT = function (desc, nodeId, itemId, planType) {
        var layer = layui.layer;
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        //iframe层
        var iframeSrc = httpUrl + '/api/sdstool/showASMT?modifyUserId=' + params.userCode + '&modifyUserName=' + encodeURIComponent(params.userName) +
            '&locId=' + params.deptCode + '&episodeId=' + params.episodeId + '&entityId=' + qcentity.id + '&nodeId=' + nodeId.replace("|", "$") + '&itemId=' + itemId + '&desc=' + encodeURIComponent(desc);
        var index = layer.open({
            id: 'lay_scale',
            type: 2,
            title: '<i class="layui-icon">&#xe62a;</i> ' + desc,
            // offset: 'r',
            skin: 'layer-ext-myskin',
            // anim: 3, //0-6的动画形式
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['80%', '80%'],
            content: iframeSrc + '&t='+new Date().getTime()
        });
        layui.element.init();

        //监听子页面的postMessage
        function receiveAsmtMessage(event) {
            //取得子页面传回来的值
            if (event.data == "close") {
                // 如果传回close，关闭当前弹窗
                layer.close(index);
                window.removeEventListener('message', receiveAsmtMessage, false);
            }
            if (event.data.split("#")[0] == "save") {
                $("#" + itemId).find(".score").text(event.data.split("#")[1]);
                // 后台重新判断质控内容
                owner.reloadTreatInfo();
                owner.reloadQCInfo();
                // owner.CountClick("TreatMenu");
                $("#cdss").html(planDoTips);
                $(".cdssdiv").addClass("menuSelection");
                $("#cdss").show();
                $("#batch").hide();
                owner.bindOnClick();
                // owner.hasRead(param, planType);
                // setTimeout(function (){
                //     layer.close(index);
                // },1000);
            }
        }

        window.addEventListener('message', receiveAsmtMessage, false);
    };

    /**
     * 医嘱批量处理
     * @param desc
     * @param itemStr
     * @param planType
     */
    owner.showBatchOrder = function (desc, itemStr, planType, ciitem) {
        var OrderList;
        // 获取禁忌症条目及触发信息
        $.ajax({
            url: httpUrl + "/api/sdstool/getOrderInfo",
            data: {"itemId": itemStr, "patientId": params.episodeId, "entityId": qcentity.id, "planType": planType, "ciitemId":ciitem, t:new Date().getTime()},
            async: false,
            success: function (res) {
                OrderList = res;
            }
        });

        var template = document.getElementById('ci-temp');
        var cdss = document.getElementById('cdss');
        var batch = document.getElementById('batch');
        var tempClone;
        if (document.createElement("template").content) {
            tempClone = template.content.cloneNode(true);
        } else {
            tempClone = document.createElement("div");
            tempClone.innerHTML=template.innerHTML;
        }
        var ci = tempClone.querySelector('#ciItems');
        var title = ci.querySelector('.standardWord');
        var items = ci.querySelector('.standardDesc');
        var item = items.querySelector('.hisui-checkbox');

        var l = OrderList.length;
        if (l > 0) {
            ci.innerHTML = "";
            var itemStr = "";
            for (var i = 0; i < l; i++) {
                var itemName = OrderList[i].itemName;
                var itemList = OrderList[i].itemList;

                title.innerHTML = (i + 1 + ".") + itemName;
                items.innerHTML = "";
                var options = "";
                for (var j = 0; j < itemList.length; j++) {
                    var itemObj = itemList[j];
                    var checkFlag = "";
                    if (itemObj.isActive != 0) {
                        checkFlag = "checked";
                    }
                    options += "<div style=\"width:100%; font-size: 12px;display: inline-block;\">\n";
                    options += "    <input class=\"hisui-checkbox\" type=\"checkbox\" name=\"" + itemName + "\" id=\"" + itemObj.xcode + "\" " + checkFlag + ">" + itemObj.description + "\n";
                    options += "</div>\n";
                }
                if (options == "") {
                    options = "<div style=\"font-size: 12px;\">未关联医嘱项目</div>";
                }
                items.innerHTML = options;
                itemStr += (title.outerHTML + items.outerHTML);
            }
            ci.innerHTML = itemStr;
            batch.innerHTML = "";
            if (document.createElement("template").content) {
                batch.append(tempClone);
            } else {
                $(batch).append(tempClone.innerHTML);
            }
            $.parser.parse(batch);//解析checkbox
        } else {
            batch.append("<div>未找到医嘱维护信息！</div>");
        }
        // 处理内容显示，cdss内容隐藏
        $(batch).show();
        $(cdss).hide();
    }

    /**
     * 医嘱关联处置弹出窗(批量护理)
     * @param desc
     * @param itemStr
     * @param planType
     */
    owner.showBatchOrder_Dlg = function (desc, itemStr, planType) {
        var layer = layui.layer;
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        if (qcentity.id == null) {
            layer.msg("当前患者未进入单病种质控！");
            return
        }
        if (itemStr == "") {
            layer.msg("医嘱项错误！");
            return
        }
        //iframe层
        var iframeSrc = httpUrl + '/api/sdstool/showOrder?modifyUserId=' + params.userCode + '&modifyUserName=' + params.userName + '&patientId=' + params.episodeId + '&entityId=' + qcentity.id + '&itemId=' + itemStr + '&planType=' + planType;
        var index = layer.open({
            id: 'lay_order',
            type: 2,
            title: '<i class="layui-icon">&#xe62a;</i>' + qcentity.name,
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['40%', '50%'],
            closeBtn: false,
            content: iframeSrc + '&t='+new Date().getTime()
        });
        layui.element.init();

        //监听子页面的postMessage
        function receiveOrderMessage(event) {
            //取得子页面传回来的值
            if (event.data == "close") {
                // 如果传回close，关闭当前弹窗
                layer.close(index);
                window.removeEventListener('message', receiveOrderMessage, false);
            }
            if (event.data == "save") {
                owner.hasRead(itemId, planType);
                // 后台重新判断质控内容
                owner.init();
                setTimeout(function () {
                    layer.close(index);
                }, 1000);
            }
        }

        window.addEventListener('message', receiveOrderMessage, false);
    }

    /**
     * 医嘱关联处置弹出窗
     * @param desc
     * @param itemId
     * @param planType
     */
    owner.showOrder = function (desc, itemId, planType) {
        var layer = layui.layer;
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        if (qcentity.id == null) {
            layer.msg("当前患者未进入单病种质控！");
            return
        }
        //iframe层
        var iframeSrc = httpUrl + '/api/sdstool/showOrder?modifyUserId=' + params.userCode + '&modifyUserName=' + params.userName + '&patientId=' + params.episodeId + '&entityId=' + qcentity.id + '&itemId=' + itemId + '&planType=' + planType;
        var index = layer.open({
            id: 'lay_order',
            type: 2,
            title: '<i class="layui-icon">&#xe62a;</i>' + qcentity.name,
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0, // 不显示遮罩
            area: ['40%', '50%'],
            closeBtn: false,
            content: iframeSrc + '&t='+new Date().getTime()
        });
        layui.element.init();

        //监听子页面的postMessage
        function receiveOrderMessage(event) {
            //取得子页面传回来的值
            if (event.data == "close") {
                // 如果传回close，关闭当前弹窗
                layer.close(index);
                window.removeEventListener('message', receiveOrderMessage, false);
            }
            if (event.data == "save") {
                owner.hasRead(itemId, planType);
                // 后台重新判断质控内容
                owner.reloadTreatInfo();
                setTimeout(function () {
                    layer.close(index);
                }, 1000);
            }
        }

        window.addEventListener('message', receiveOrderMessage, false);
    };

    /**
     * 文献弹窗
     * @param CureId
     */
    owner.showBook = function (treatSource,ruleBasisHtml) {
        var ev = window.event || arguments.callee.caller.arguments[0];
        if (window.event) {
            ev.cancelBubble = true;
        } else {
            ev.stopPropagation();
        }
        var bookPath = config.CDSSServer + "/api/preview?pdf=";
        layer.config({
            extend: 'myskin/style.css' //同样需要先加载新皮肤
        });
        //iframe层
        var iframeSrc = bookPath + treatSource+"&png="+ruleBasisHtml;
		if ('undefined'!==typeof websys_getMWToken){
			iFrameSrc += "&MWToken="+websys_getMWToken()
		}
        var index = layer.open({
            id: 'lay_cdss',
            type: 2,
            title: '<i class="layui-icon" >&#xe66f;</i> 文献信息',
            // offset: 'r',
            skin: 'layer-ext-myskin',
            shadeClose: true,
            shade: 0.1, // 显示遮罩
            area: ['80%', '80%'],
            content: encodeURI(iframeSrc)
        });
        layui.element.init();
    };

    function writeToInput(data){
        try{
            // var input = $("input:focus,textarea:focus");
            var input = document.getSelection().baseNode.children[0]
            if(input.tagName=="TEXTAREA"||input.tagName=="INPUT"){
                var inputval = $(input).val()
                $(input).val(inputval+data)
                $(input).focus()
            }
        }catch(e){
            layer.msg("请先选择您要写回到病历中的位置！");
        }
    }

    //写回到His
    owner.WriteToHis = function (item, ProType, Type) {
        var subTxt = item.itemDate+" 进行"+item.ItemName+"评估,结果："+item.itemScore +" " + item.itemLevel
        writeToInput(subTxt)
    }

    /**
     * 处理完成
     * @param id
     * @param type
     */
    owner.hasRead = function (id, type) {
        doItem = id;
        $("#" + id).remove(); // 移除元素
        // switch (type) { // 重新计算信息数目
        //     case "plan":
        //         planDoTipsNum--;
        //         $("span.planDoTips").text(planDoTipsNum);
        //         break;
        //     case "qc":
        //         qcTipsNum--;
        //         $("span.qcTips").text(qcTipsNum);
        //         break;
        //     case "inOut":
        //         inOutTipNum = 0;
        //         inOutTip = "";
        //     default:
        //         break;
        // }
        // tipsNum--;
        // if (tipsNum == 0) {
        //     $(".alarm").text(tipsNum).hide();
        // } else {
        //     $(".alarm").text(tipsNum).show();
        // }
    };

    // 锚点的跳转方法
    owner.goAnchor = function (selector, Module, ProType) {
        // this.CountClick("查看",Module,ProType,"","","","")
        var _this = this
        if (document.querySelector(selector)) {
            document.querySelector('#cdss').scrollTop = document.querySelector(selector).offsetTop - 30
        } else {
            setTimeout(function () {
                _this.goAnchor(selector)
            }, 500)
        }
    };


    /**
     * 浮窗内容事件绑定
     */
    owner.boxEvent = function () {
        // 标题栏鼠标悬浮动作事件
        $(".maodiantitle").mouseover(function () {
            $(this).children("div").show();
        });
        $(".maodiantitle").mouseleave(function () {
            $(this).children("div").hide();
        });
    }();

    /**
     * 工具栏的展开与折叠
     */
    owner.displayArea = function (e) {
        $(".icon").toggleClass("notShow")
        $("#expand").toggleClass("fa-rotate-180")
        $("#toolbar").toggleClass("zoomOut")
    };
    /**
     * 设置悬浮窗口移动且磁性吸附
     */
    owner.dragElement = function () {
        var dragging = false
        var boxX, boxY, mouseX, mouseY, offsetX, offsetY
        var box = document.getElementById("toolbar")
        var box1 = document.body

        // 定义常量吸附范围
        var RANGE = 100

        // 鼠标按下的动作
        box.onmousedown = down
        // 鼠标的移动动作
        document.onmousemove = move
        // 释放鼠标的动作
        document.onmouseup = up

        // 鼠标按下后的函数,e为事件对象
        function down(e) {
            dragging = true

            // 获取元素所在的坐标
            boxX = box.offsetLeft
            boxY = box.offsetTop

            // 获取鼠标所在的坐标
            mouseX = parseInt(getMouseXY(e).x)
            mouseY = parseInt(getMouseXY(e).y)

            // 鼠标相对元素左和上边缘的坐标
            offsetX = mouseX - boxX
            offsetY = mouseY - boxY
        }

        // 鼠标移动调用的函数
        function move(e) {
            if (dragging) {
                document.body.onselectstart = function () {
                    return false;
                }

                // 获取移动后的元素的坐标
                var x = getMouseXY(e).x - offsetX
                var y = getMouseXY(e).y - offsetY

                // 计算可移动位置的大小， 保证元素不会超过可移动范围
                // 此处就是父元素的宽度减去子元素宽度
                var width = box1.clientWidth - box.offsetWidth
                var height = box1.clientHeight - box.offsetHeight

                // min方法保证不会超过右边界，max保证不会超过左边界
                x = Math.min(Math.max(0, x), width)
                y = Math.min(Math.max(0, y), height)

                // 磁性吸附部分
                if (x < RANGE) {
                    x = 0
                }
                if (width - x < RANGE) {
                    x = width
                }
                if (y < RANGE) {
                    y = 0
                }
                if (height - y < RANGE) {
                    y = height
                }

                // // 上下和左右吸附形状
                // if ((x < RANGE||width - x < RANGE)&&(y!=0||y!=height)) {
                //     box.style.width = '40px'
                //     box.style.height = '200px'
                // } else if ((y < RANGE||height - y < RANGE)&&(x!=0||x!=width)) {
                //     box.style.width = '200px'
                //     box.style.height = '40px'
                // }

                // 给元素及时定位
                box.style.left = x + 'px'
                box.style.top = y + 'px'
            }
        }

        // 释放鼠标的函数
        function up(e) {
            dragging = false
        }

        // 函数用于获取鼠标的位置
        function getMouseXY(e) {
            var x = 0, y = 0
            e = e || window.event

            if (e.pageX) {
                x = e.pageX
                y = e.pageY
            } else {
                x = e.clientX + document.body.scrollLeft - document.body.clientLeft
                y = e.clientY + document.body.scrollTop - document.body.clientTop
            }
            return {
                x: x,
                y: y
            }
        }
    }
    /*ie map()方法*/
    if (!Array.prototype.map) {
        Array.prototype.map = function (callback, thisArg) {
            var T, A, k;
            if (this == null) {
                throw new TypeError(" this is null or not defined");
            }
            var O = Object(this);
            var len = O.length >>> 0;
            if (typeof callback !== "function") {
                throw new TypeError(callback + " is not a function");
            }
            if (thisArg) {
                T = thisArg
            }
            A = new Array(len);
            k = 0;
            while (k < len) {
                var kValue, mappedValue;
                if (k in O) {
                    kValue = O[k];
                    mappedValue = callback.call(T, kValue, k, O);
                    A[k] = mappedValue
                }
                k++
            }
            return A
        }
    }
    if(!Array.prototype.push) {
        Array.prototype.push = function(){
            for (var i = 0; i < arguments.length; i++) {
                this[this.length] = arguments[i];
                return this.length;
            }
        }
    }
    /*IE indexOf */
    if (!Array.prototype.indexOf) {
        Array.prototype.indexOf = function(searchElement, fromIndex) {
            var k;
            if (this == null) {
                throw new TypeError('"this" is null or not defined');
            }
            var O = Object(this);
            var len = O.length >>> 0;
            if (len === 0) {
                return -1;
            }
            var n = fromIndex | 0;
            if (n >= len) {
                return -1;
            }
            k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
            while (k < len) {
                if (k in O && O[k] === searchElement) {
                    return k;
                }
                k++;
            }
            return -1;
        };
    }
}(jQuery, window.SdsTool = {}));